Python Program to reverse a string using recursion
In this program, you will learn how to reverse a string using recursion in Python.
C++ => ++C
Python => nohtyp
Example: How to reverse a string using recursion in Python
def reversestring(st):
if len(st) == 0:
return st
else:
return reversestring(st[1:]) + st[0]
st = input("Enter a string:")
revstr = reversestring(st)
print("After reverse string:", revstr)
Output:
Enter a string:xiith
After reverse string: htiix