reverse words in string python code example
Example 1: python reverse string
'String'[::-1]
Example 2: how to reverse word order in python
string = "I am a python programmer"
words = string.split()
words = list(reversed(words))
print(" ".join(words))
Example 3: reverse each word in a string python
def reverse_word_sentence (sentence):
return ' '.join(word[::-1] for word in sentence.split(" "))
Example 4: python reverse a string
def reverse(s):
str = ""
for i in s:
str = i + str
return str
'hello world'[::-1]