Python Program to Reverse a String Using Recursion














































Python Program to Reverse a String Using Recursion



Description:

What is the Recursion Function?

A Recursion is a function that calls itself during its execution.

So, how to reverse a string using recursion?

String Recursion will take place with the help of len() function and slicing of string.

len() returns the length of a string

For better understanding do have a look on below pictures






.





Input Code: 

def rev(s):
if len(s) == 0:
return s
else:
return rev(s[1:]) + s[0]
n= str(input(
"Enter the string to be reversed: "))
print(rev(n))


Output

Enter the string to be reversed: cppsecrets
stercesppc

Comments