Python Practice › String Programs › Program 37
Swap the first and last letters of a string
Write a Python program to exchange the first and last letters of a string.
Input
"We are learning python"
Output
ne are learning pythoW
Approach
- last + middle + first.
Solution
text = "We are learning python"print(text[-1] + text[1:-1] + text[0])Output
ne are learning pythoW
Learn the concept
New to this topic? Read the lesson, then come back.