• 技术文章 >Python技术 >Python基础教程

    python怎么判断大小写

    爱喝马黛茶的安东尼爱喝马黛茶的安东尼2019-10-12 15:04:17原创25114

    Python提供了isupper(),islower(),istitle()方法用来判断字符串的大小写,具体实例如下:

    >>> str_1 = "HELLO PYTHON" # 全大写
    >>> str_2 = "Hello PYTHON" # 大小写混合
    >>> str_3 = "Hello Python" # 单词首字母大写
    >>> str_4 = "hello python" # 全小写

    isupper() 判断是否全是大写

    >>> str_1.isupper()
    True
    >>> str_2.isupper()
    False
    >>> str_3.isupper()
    False
    >>> str_4.isupper()
    False

    相关推荐:《Python入门教程

    islower() 判断是否全是小写

    >>> str_1.islower()
    False
    >>> str_2.islower()
    False
    >>> str_3.islower()
    False
    >>> str_4.islower()
    True

    istitle() 判断首字母是否大写,其余的是否小写

    >>> str_1.istitle()
    False
    >>> str_2.istitle()
    False
    >>> str_3.istitle()
    True
    >>> str_4.istitle()
    False
    专题推荐:python 判断 大小写
    上一篇:python怎么去除换行符 下一篇:python深拷贝和浅拷贝的区别是什么

    相关文章推荐

    • Python中怎么转换字符串大小写• 一文搞定Python大小写转换,首字母大写,去除特殊字符• python字符串大小写转换的方法是什么

    全部评论我要评论

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

  • 取消发布评论
  • 

    Python学习网