reverse words in python code example
Example 1: how to reverse word order in python
## initializing the string
string = "I am a python programmer"
## splitting the string on space
words = string.split()
## reversing the words using reversed() function
words = list(reversed(words))
## joining the words and printing
print(" ".join(words))
Example 2: reverse the words in a string python
string = 'hello people of india'
words = string.split() #converts string into list
print(words[::-1])