reverse a given string in python code example
Example 1: python reverse string
'String'[::-1] #-> 'gnirtS'
Example 2: reverse string python recursion
def reverse(string):
if len(string) == 0:
return string
else:
return reverse(string[1:]) + string[0]
a = str(input("Enter the string to be reversed: "))
print(reverse(a))