Python Practice › String Programs › Program 62
Strip spaces
Write a Python program to remove leading and trailing spaces.
Input
" sqaltoolspythonfun "
Output
'sqaltoolspythonfun' 'sqaltoolspythonfun ' ' sqaltoolspythonfun'
Approach
strip();lstrip()/rstrip()for one side.
Solution
text = " sqaltoolspythonfun "print(repr(text.strip()), repr(text.lstrip()), repr(text.rstrip()))Output
'sqaltoolspythonfun' 'sqaltoolspythonfun ' ' sqaltoolspythonfun'
Learn the concept
New to this topic? Read the lesson, then come back.