The following English instructions are given by the official:
String.strip (s[, chars])
Return a copy of the string with Leadingand trailing characters removed. If chars is omitted ornone, whitespace characters is removed. If given and not None, chars must is astring; The characters in the string would be stripped from the both ends of thestring this method was called on.
if chars is ignored or None, the white space string is removed. If the chars is not none and exists, the chars of the string's tail- ends will be removed.
Changed in version 2.2.3:the Charsparameter is added. The chars parameter cannot is passed in earlier 2.2versions.
The characters in the following example are tab -header and end with a space.
Line= ' Hello happybks! ‘
print ' * ' +line.strip () + ' * '
print ' * ' +line.strip (') + ' * '
print ' * ' +line.strip (') + ' * '
print ' * ' +line.strip (' h ') + ' * '
The output results are as follows:
*hello happybks!*
*hello happybks!*
*hello happybks!*
* Hello happybks! *
can be found to not pass parameters, will be the beginning and end of the string of the space,tab All Delete, the middle of the space and tab will not
If you pass a space or tab argument, the substring will still delete the beginning and end of the string, regardless of the space or tab.
When the passed argument is a different argument, the string at the beginning of the argument is not the string, then there is no effect
However, if the beginning and end of the string are other strings, and the passed arguments are the same string, the string at the beginning and end of the strings is cleared, regardless of the number of arguments. But case sensitive.
For example, the following example:
Line2= ' Haaaaahhaaaaaaahhhhh '
print ' * ' +line2.strip (' h ') + ' * '
Result output:
*aaaaahhaaaaaaahh*
This article is from the "90SirDB" blog, be sure to keep this source http://90sirdb.blog.51cto.com/8713279/1812431
Python Str.strip () function