Python Practice › String Programs › Program 26

Reverse each word

EasyString Programs · 26 of 106

Write a Python program to reverse each word of a string, keeping the word order.

Advertisement
Input
"sqatools python"
Output
slootaqs nohtyp

Approach

  1. Reverse every word and join them back.

Solution

Python
text = "sqatools python"print(" ".join(w[::-1] for w in text.split()))
Output
slootaqs nohtyp
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs