Python Practice › String Programs › Program 26
Reverse each word
Write a Python program to reverse each word of a string, keeping the word order.
Input
"sqatools python"
Output
slootaqs nohtyp
Approach
- Reverse every word and join them back.
Solution
text = "sqatools python"print(" ".join(w[::-1] for w in text.split()))Output
slootaqs nohtyp
Learn the concept
New to this topic? Read the lesson, then come back.