Reverse a word in python | Letters in word and Sentences

It a very easy to Reverse words in a string python, you have to first Separate each word, then Reverse the word separated list and in the last join each word with space.

For all this step you needed a split(), join() , reversed() function and list data structure.

Algorithm of reverse words in a sentence

  1. Initialize the string.
  2. Split the string on space and store the resultant list.
  3. Reverse the list words.
  4. Convert the result to the list.
  5. Join the words using the join function and print it.

Example of Reverse words in a given String in Python

Output: language Programming Python A

Q: How to Python reverse letters in a word?

Answer:

Reverse letters in words and sentence both:

In example taking user input, you can use any sentences.

Output:

Reverse only letters in word

Q: Write a python program that accepts a word from the user and reverse it.

Answer: Example of that accepts a word from the user and reverse it.

Q: How to reverse a string in python using for loop?

Answer:

Read More: Python reverse string | Using loop, recursion, stack, slice, reversed

Do comment if you have any doubts and suggestion on this tutorial.

Note:
IDE: PyCharm 2020.1.1 (Community Edition)
macOS 10.15.4
Python 3.7
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.