1)USING FOR LOOP❤️
def reverse(string):
rev_string=""
for i in string:
rev_string= i+rev_string
print("reversed string:",rev_string)
string="kishan"
reverse(string)
2) USING RECURSION🚇
def reverse(s):
if len(s) == 0:
return s
else:
return reverse(s[1:]) + s[0]
s = "hello brain"
print ("The original string is : ",end="")
print (s)
print ("The reversed string(using recursion) is : ",end="")
print (reverse(s)
Top comments (0)