May 10, 2021 Python2
Scene:
Remove the spaces before and after the string
You can use the strip, lstrip, rstrip method
>>> a="abc".center (30)
>>> a
' abc '
>>> b=a.lstrip ()
>>> b
'abc '
>>> c=a.rstrip ()
>>> c
' abc'
>>> d=a.strip ()
>>> d
'abc'
>>>
The default of these three methods is to remove spaces, or you can remove other characters by parameters, equivalent to replace
>>> a="abc"
>>> b=a.strip ('a')
>>> b
'bc'
>>> c=a.replace ('a','')
>>> c
'bc'
>>>