博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

python学习之strip()

Posted on 2017-10-12 16:13  开飞机的贝塔  阅读(186)  评论(0编辑  收藏  举报

定义:

Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)。

语法:

str.strip([chars]);

返回值:

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

例子:

>>> str = "0000000this is string example....wow!!!0000000"
>>> str.strip('0')
'this is string example....wow!!!'