• 技术文章 >常见问题 >Python常见问题

    用python如何判断字符的大小写

    yangyang2020-05-09 10:30:06原创12043

    Python提供了isupper(),islower(),istitle()方法用来判断字符串的大小写。

    1、isupper()方法

    Python isupper() 方法检测字符串中所有的字母是否都为大写。

    示例:

    str = "THIS IS STRING EXAMPLE....WOW!!!"; 
    print str.isupper();
    
    str = "THIS is string example....wow!!!";
    print str.isupper();

    输出如下:

    True
    False

    2、islower()方法

    Python islower() 方法检测字符串是否由小写字母组成。

    islower()方法语法:str.islower()

    示例:

    str = "THIS is string example....wow!!!"; 
    print str.islower();
    
    str = "this is string example....wow!!!";
    print str.islower();

    输出如下:

    False
    True

    3、istitle()方法

    Python istitle() 方法检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写。

    istitle()方法语法:str.istitle()

    示例:

    str = "This Is String Example...Wow!!!";
    print str.istitle();
    
    str = "This is string example....wow!!!";
    print str.istitle();

    输出如下:

    True
    False

    更多Python知识请关注Python视频教程栏目。

    专题推荐:python
    品易云
    上一篇:怎样用python计算矩阵乘法? 下一篇:linux用什么编辑器写python?

    相关文章推荐

    • windows下如何安装Python的库?• python怎么把矩阵最后一行删掉?• python怎么保存生成的图像?• python如何获取打开文件的行数?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网