美文网首页
【转】Python之strip

【转】Python之strip

作者: yuanCruise | 来源:发表于2017-07-10 12:23 被阅读10次

函数原型
声明:s为字符串,rm为要删除的字符序列
s.strip(rm) 删除s字符串中开头、结尾处,位于 rm删除序列的字符
s.lstrip(rm) 删除s字符串中开头处,位于 rm删除序列的字符
s.rstrip(rm) 删除s字符串中结尾处,位于 rm删除序列的字符
注意:

  1. 当rm为空时,默认删除空白符(包括'\n', '\r', '\t', ' ')
    例如:

复制代码代码如下:

a = ' 123'>>> a.strip()'123'>>> a='\t\tabc''abc'>>> a = 'sdff\r\n'>>> a.strip()'sdff'

2.这里的rm删除序列是只要边(开头或结尾)上的字符在删除序列内,就删除掉。
例如 :

复制代码代码如下:

a = '123abc'>>> a.strip('21')'3abc' 结果是一样的>>> a.strip('12')'3abc'

相关文章

  • 【转】Python之strip

    函数原型声明:s为字符串,rm为要删除的字符序列s.strip(rm) 删除s字符串中开头、结尾处,...

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

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

  • Python

    python string strip, removes all whitespace at beginning ...

  • python strip()

    声明:s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头、结尾处,位于 rm删除序列的...

  • Python strip()方法

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

  • Python 文件读写

    或者 或者使用Python内置函数 .strip() 和 .split()函数,进行分割比如:由于在python...

  • python: strip()函数

    函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头、结尾...

  • Python strip()函数

    函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头、结尾...

  • python strip()函数

    s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头、结尾处,位于 rm删...

  • python strip( )函数

    一、默认用法:去除空格 str.strip() :去除字符串两边的空格 str.lstrip() :去除字符串左边...

网友评论

      本文标题:【转】Python之strip

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