Problem in python programming
for i in x:
print(y) How does the order of y=i+y & y=y+i is different? pls explain how 1st condition give a reverse string ? Thank you!
in the example you're referring to, we want to reverse a string:
word = input('Please enter a word:> ')
reverse_string = ''
for char in word:
reverse_string = reverse_string + char
So, we iterate over each 'char' (or character) in the string and we append it backwards using reverse string. That's why we need the order char + reverse_string.
If we had reverse_string + char instead, we'd print back the exact same string we input, without reversing it.
In the future, could you please make sure to include a link to the lecture your question is about? It would make it a lot easier to answer the questions, especially since you're naming your variables differently.