zoukankan      html  css  js  c++  java
  • python中字符串操作

    (1)字符串剔除空格

        string.strip()    ---> 去除字符串首尾空格(字符串中间的空格不会被删除)

        string.lstrip()   ---> 去除字符串首部空格(字符串首部的一个或多个空格)

        string,rstrip()   ---> 去除字符串尾部的空格

        例:'   abcdf  '.strip()

        输出结果:'abcdf'

    (2)字符串剔除字符或子串

        'ab1234ab5678ab'.strip('ab')  ---> 结果为: '1234ab5678'

        'a123456a'.strip('a')    ---> 结果为: '123456'

        'a123456a'.lstrip('a')   ---> 结果为: '123456a'

        'a123456a'.rstrip('a')   ---> 结果为: 'a123456'

    (3)将字符串中凡是大写的转为小写

        string.lower()

        例:'Adfs1234Bsdf78D'.lower()

        输出结果: 'adfs1234bsdf78d'

    (4)将字符串中凡是小写的转为大写

        string.upper()

        例:   'Adfs1234Bsdf78D'.upper()

        输出结果为:'ADFS1234BSDF78D'

     (5)字符串比较忽略大小写的方法

        if 'Python'.lower() == 'PYThon'.lower():

            print 'true'

        else:

            print 'false'

        输出结果为: true

        

  • 相关阅读:
    supervise 用来监控服务,自动启动
    tee -a /var/log/jd.log
    类的构造函数与析构函数的调用顺序
    c++之带默认形参值的函数
    zoj1001-A + B Problem
    zoj1037-Gridland
    cf499A-Watching a movie
    cf478B-Random Teams 【排列组合】
    C++版修真小说
    Python_12-线程编程
  • 原文地址:https://www.cnblogs.com/xiehy/p/10564413.html
Copyright © 2011-2022 走看看