Strip in python is used to remove the first character of a string. Similarly, lstrip is used to remove the character on the left, and rstrip is used to remove the character on the right. All three functions can be passed in a parameter, specifying the first and last characters to be removed. Note that an array of characters is passed in. the compiler removes all corresponding characters at both ends until no matching characters exist, for example:
Thestring = ' Saaaay Yes No yaaaass '
Print Thestring. Strip ( ' Say ' )
ThestringRemove characters from the ['s ', 'A', 'y'] array until the characters are not in the array.Therefore, the output result is:
Yes No
The principle of lstrip is the same as that of rstrip. Note: When no parameters are input, spaces at the beginning and end are removed by default.
Thestring = ' Saaaay Yes No yaaaass '
Print Thestring. Strip ( ' Say ' )
Print Thestring. Strip ( ' Say ' ) # There is a space behind say
Print Thestring. lstrip ( ' Say ' )
Print Thestring. rstrip ( ' Say ' )
Running result: Yes No
Es no
Yes No yaaaass
Saaaay Yes No
Python daily delicious series (total)
Python daily delicious (4)-isinstance determines the object type
Python daily delicious (5)-ljust just Center
Python daily delicious (6)-strip lstrip rstrip
Python daily delicious (7)-join string (join %)
Python daily delicious (8)-character inversion in strings
..