Function: Strip () Lstrip () Rstrip ()
Action: Removes spaces or specified characters from a string
One, default usage: Remove space
Str.strip (): Remove spaces on both sides of the string
Str.lstrip (): Remove the space on the left side of the string
Str.rstrip (): Remove the space to the right of the string
Note: The space here contains ' \ n ', ' \ R ', ' \ t ', '
Default Usage Instance
>>> Dodo = "Hello boy"
>>> dodo.strip ()
' Hello Boy '
>>> dodo.lstrip ()
' Hello boy '
>>> dodo.rstrip ()
' Hello Boy ' </span>
Ii. removal of specified characters
str.strip (' Do '): Remove characters specified at both ends of the string
Str.lstrip (' Do '): To remove the character specified on the left
Str.rstrip (' Do '): To remove the specified character on the right
Three functions can pass in an argument (here, for example, "do"), specifying the first and last characters to be removed, the compiler removes all the corresponding characters from both ends until no matching characters
Note:
1. Remove the specified characters can not appear at the end of the space, or incoming parameters need to add a space
2. A combination of specified character representations, such as ' do ' means ' dd ', ' do ', ' od ', ' oo ', ' ddd ', ' ooo ', etc.
Remove character instances
>>> Dodo = "Say hello say boy Saaayaaas"
>>> dodo.strip (' say ')
' hello say boy '
>>> ; Dodo.strip (' yas ')
' hello say boy '
#当传入的参数中加入空格时
>>> Dodo.strip (' say ')
' hello say bo '
>>> dodo.lstrip (' say ')
' hello say boy ' C10/>>>> Dodo.rstrip (' say ')
' Say hello say boy '