python当中strip()是起什么作用的?举例说明一下,谢谢

如题所述

告知你一个捕鱼的方法:
>>> import string
>>> help(string.strip)
Help on function strip in module string:
strip(s, chars=None)
strip(s [,chars]) -> string

Return a copy of the string s with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping.
用help()查询 模块,方法等的用途。
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-01-07
string.rstrip(s[,
chars])
Return a copy of the string with trailing characters removed. If
chars is omitted or None, whitespace characters are removed. If given and not
None,
chars must be a string; the characters in the string will be stripped from the end of the string this method is called on.
例子:
s='abcdefg'
s=s.strip("asbdg")
print s
结果为'cdef'
默认的是去除空白字符包括' ','\t','\n'等
第2个回答  2013-01-06
去掉字符串前后空格
第3个回答  2013-01-06
去掉前后的空格
第4个回答  推荐于2017-05-16
s=" fsdkjfdkfk kdf ls kfjsdlk "
s=s.strip()
结果s就是"fsdkjfdkfk kdf ls kfjsdlk"前后空格都没了,但中间间隔还保留。本回答被网友采纳
相似回答