reverse words in string in python code example
Example 1: python reverse string
'String'[::-1] #-> 'gnirtS'
Example 2: Python reverse a string
# Library
def solution(str):
return ''.join(reversed(str))
# DIY with recursion
def solution(str):
if len(str) == 0:
return str
else:
return solution(str[1:]) + str[0]