reverse a word in a string python code example
Example 1: reverse each word in a string python
def reverse_word_sentence (sentence):
return ' '.join(word[::-1] for word in sentence.split(" "))
# Input: "Split Reverse Join"
# Output: "tilpS esreveR nioJ"
Example 2: reverse the words in a string python
string = 'hello people of india'
words = string.split() #converts string into list
print(words[::-1])