版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_40244153/article/details/79747711
Python strip() 方法用于
移除字符串头尾指定的字符(默认为空格)。
语法:str.strip([chars]);
参数:chars -- 移除字符串头尾指定的字符。
语法:str.strip([chars]);
参数:chars -- 移除字符串头尾指定的字符。
返回值:返回移除字符串头尾指定的字符生成的新字符串。
实例:
>>> str="00000 run0bb 00000" #移除字符串首尾指定的所有字符,中间的不移除
>>> str.strip('0')
' run0bb '
>>> str=" ddddd "
>>> str.strip(' ')
'ddddd'