字符串的 strip()方法 2018-10-04

描述

字符串的 strip([chars])方法用来移除字符串头尾指定的字符(默认为空格或者换行符)或字符序列

参数

字符或者字符串,默认为空格或者换行符

返回值

返回移除字符串头尾指定的字符生成的新字符串

实例

>>> str = '00000012345670000'
>>> print str.strip('0')
1234567
>>> str = '   1234567   '
>>> print str.strip()
1234567
>>> str = '12345612'
>>> print str.strip('12')
3456
>>> str = '123456121'
>>> print str.strip('12')
3456

注意:只要头尾包含有指定字符序列中的字符就删除

posted @ 2018-10-04 14:22  默写年华  阅读(1252)  评论(0编辑  收藏  举报