zoukankan      html  css  js  c++  java
  • upper lower capitalize and title

    转换大小写

    和其他语言一样,Python为string对象提供了转换大小写的方法:upper() 和 lower()。还不止这些,Python还为我们提供了首字母大写,其余小写的capitalize()方法,以及所有单词首字母大写,其余小写的title()方法。函数较简单,看下面的例子:

    = 'hEllo pYthon'
    print s.upper()
    print s.lower()
    print s.capitalize()
    print s.title()


    输出结果:
    HELLO PYTHON
    hello python
    Hello python
    Hello Python

    判断大小写

    Python提供了isupper(),islower(),istitle()方法用来判断字符串的大小写。注意的是:
    1. 没有提供 iscapitalize()方法,下面我们会自己实现,至于为什么Python没有为我们实现,就不得而知了。
    2. 如果对空字符串使用isupper(),islower(),istitle(),返回的结果都为False。

    print 'A'.isupper() #True
    print 'A'.islower() #False
    print 'Python Is So Good'.istitle() #True
    #
    print 'Dont do that!'.iscapitalize() #错误,不存在iscapitalize()方法

    作者:CoderZhCoderZh的技术博客 - 博客园
    出处:http://coderzh.cnblogs.com/

  • 相关阅读:
    python
    redis
    mongodb replica on aws ec2
    mysql
    java正则表达式
    终端make命令和Git学习
    linux和shell学习
    centos普通用户安装jenkins
    centos7普通用户安装jdk
    WPF动画
  • 原文地址:https://www.cnblogs.com/allenblogs/p/1771176.html
Copyright © 2011-2022 走看看