for loop to reverse a string python code example
Example 1: reverse string in python
'hello world'[::-1]
'dlrow olleh'
Example 2: python iterate through string in reverse
for c in reversed(string):
print c
Example 3: print string in reverse order uing for loop python
# reversing a sring using recursion
def reverse_recursion(s):
if len(s) == 0:
return s
else:
return reverse_recursion(s[1:]) + s[0]