reverse words in a string python code example
Example 1: how to reverse a string in python
string = "racecar"
print(string[::-1])
Example 2: python reverse string
'String'[::-1]
Example 3: how to reverse word order in python
string = "I am a python programmer"
words = string.split()
words = list(reversed(words))
print(" ".join(words))
Example 4: how to reverse a string in python
'your sting'[::-1]
Example 5: python reverse a string
def reverse(s):
str = ""
for i in s:
str = i + str
return str
'hello world'[::-1]
Example 6: Python reverse a string
def solution(str):
return ''.join(reversed(str))
def solution(str):
if len(str) == 0:
return str
else:
return solution(str[1:]) + str[0]