We often encounter a lot of whitespace in the processing of the problem, a one to remove the manual is not what we programmers should do, today this tip of the article play snake nets to tell you, if you use Python to remove the space on both sides of the string.
Let's first create a string variable that has n spaces around it, see the code:
>>> s = "Iplaypython">>>
Remove the string space, in Python has its built-in method, do not need us to build the wheel.
Lstrip
This string method removes the space before the start position of the string s.
>>> S.lstrip ()"
Rstrip
This built-in method can delete all the spaces at the end of the string and see the following demo code:
>>> S.rstrip ()' iplaypython'
Strip
Sometimes we read the contents of the file, there are spaces on both sides of each line, can be removed all at once, the word character has a built-in strip () method to do.
>>> s = "Iplaypython">>> s.strip ()'iplaypython'
Python removes spaces at both ends of a space string