I saw it today.
Http://www.pythondoc.com/pythontutorial27/datastructures.html#tut-tuples
5.1.4, there is a paragraph:
?
123 |
>>> freshfruit
=
[
‘ banana‘
,
‘ loganberry ‘
,
‘passion fruit ‘
]
>>> [weapon.strip()
for weapon
in
freshfruit]
[
‘banana‘
,
‘loganberry‘
,
‘passion fruit‘
]
|
Think of the use of strip ().
The following excerpt from http://www.cnblogs.com/kaituorensheng/archive/2013/05/23/3096028.html
Function prototypes
declaration : S is a string, RM is a sequence of characters to be deleted
S.strip (RM) Remove the characters from the beginning and end of the s string in the RM delete sequence
S.lstrip (RM) Delete the character in the S string at the beginning of the RM delete sequence
S.rstrip (RM) Removes the character from the end of the S string that is located in the RM delete sequence
Note :
1. When RM is empty, the default is to remove the whitespace characters (including ' \ n ', ' \ R ', ' \ t ', ')
For example:
2. The RM delete sequence here is deleted as long as the character on the edge (beginning or end) is within the delete sequence.
For example:
1 ' 123ABC ' 2 a.strip ('+ ')3 >>>'3abc ' 4 A.strip ('5 ') >>>' 3ABC'
The result is the same.
More Intuitive: RM content, as long as at both ends, will be caught out, but if you encounter a character that is not in RM, it will stop to the middle of the search (the search will not stop, you can always go to the left or to the right).
Examples are as follows:
?
1234567 |
>>> b = ‘211111‘ >>> b.strip( ‘1‘ ) ‘2‘ >>> a = ‘1234516‘ >>> a.strip( ‘12‘ ) ‘34516‘ |
The first paragraph demonstrates the constant retrieval and removal of characters, and the second paragraph demonstrates stopping the search.
The returned value did not remove the second-to-last 1, the left 1 is removed, and the second character 2 is also removed from the RM.
The ' 6 ' on the right is like a wall that protects the second-to-last ' 1 '.
Well, I also know it's a very simple thing. HHH, write down consolation, this is the first, I hope not the last article,
Hello world!
Usage of "Python" strip ()