How to reverse a string in a given sentence. a. Example: Given string is “ Ram is learning in CCBP Intensive course”. Reverse the word “learning” in the above sentence
def reverse(s):
if len(s) == 0:
return s
else:
return reverse(s[1:]) + s[0]
string =("Ram is learning in CCBP Intensive course").split(" ")
print("The reverse of learning is: "+reverse(string[2]))
string[2] = reverse(string[2])
str1 = " "
for i in string:
str1 += i +" "
print(str1)
Comments
Leave a comment