美文网首页
2018-07-06-Python strip()方法

2018-07-06-Python strip()方法

作者: 日本邦 | 来源:发表于2018-07-06 10:03 被阅读16次

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

不能删除中间部分的字符。

strip()方法语法:

str.strip([chars]);       #chars -- 移除字符串头尾指定的字符序列。

以下实例展示了strip()函数的使用方法:

str='0000001200000034000000'

print (str.strip('0'))        #把str中首尾的0都去掉。

以上代码的打印结果是:

1200000034

思考以下代码的打印结果:

str='                 234              '

str=' 1234 ' print(str.strip())

相关文章

  • 2018-07-06-Python strip()方法

    Python strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列。 不能删除中间部分...

  • strip()方法

    Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)或字符序列。 注意:该方法只能删除开头...

  • Python strip()方法

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

  • python之函数常用小技巧

    1. 字符串处理方法:strip()函数 1.1 原型及使用方法 1.2 strip()函数的常用扩展 2. ra...

  • Python strip()、split()和rstrip()方

    1. Python strip() 语法描述: Python strip() 方法用于移除字符串头尾指定的字符(默...

  • Python strip()方法

    描述 Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)或字符序列。 注意:该方法只能删...

  • Python strip()方法

    strip()方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列 注意:该方法只能删除开头或者是结尾...

  • 3-3如何去掉字符串中不需要的字符

    使用字符串strip()方法 strip()方法可以用来去掉字符串开始和结尾的空白,lstrip()只去掉左边的,...

  • 字符串的清除方法

    字符串的清除方法有:strip(),lstrip(),rstrip(), 1.strip():清除字符串两边 ...

  • Python_去除字符串中的空格

    作者:Gakki 01. strip() 方法 strip() :用于移除字符串头尾指定的字符(默认为空格)或字符...

网友评论

      本文标题:2018-07-06-Python strip()方法

      本文链接:https://www.haomeiwen.com/subject/fxkvuftx.html