Answers for "how to reverse words in a string python"

6

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))
Posted by: Guest on June-11-2020
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"
Posted by: Guest on March-08-2021
29

how to reverse a string in python

# in order to make a string reversed in python 
# you have to use the slicing as following

string = "racecar"
print(string[::-1])
Posted by: Guest on November-26-2020

Code answers related to "how to reverse words in a string python"

Python Answers by Framework

Browse Popular Code Answers by Language