• python之字符串strip、rstrip、lstrip的方法


    1.描述

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

    rstrip():用于移除字符串右边指定的字符(默认为空格或换行符)或字符序列

    lstrip():用于移除字符串左边指定的字符(默认为空格或换行符)或字符序列

    2.语法

    str.strip( '[chars]' )

    str.rstrip( '[chars]' )

    str.lstrip( '[chars]' )

    3.参数

    参数chars表示需要移除字符串头尾/左边/右边指定的字符序列

    4.返回值

    返回移除字符串头尾/右边/左边指定的字符生成的新字符串

    5.实例

    str1 = "000000321456Maple123456000000"
    new_str = str1.strip( '0' )
    print(new_str)
    
    str2 = "      Maple123      "
    new_rstr = str2.rstrip()
    new_lstr = str2.lstrip()
    print(new_rstr)
    print(new_lstr)
    
    #输出结果如下:
    321456Maple123456
          Maple123
    Maple123      
    
  • 相关阅读:
    正则表达式复习 (?<=) (?=)
    HTML 30分钟入门教程
    C# 多线程详解
    C# List
    C# 枚举
    C# 线程数
    C# 泛型2
    C# 泛型
    C# 结构体
    不用Google Adsense的84个赚钱方法
  • 原文地址:https://www.cnblogs.com/Heroge/p/13181707.html
Copyright © 2020-2023  润新知