品易云推流 关闭
文章详情页
文章 > Python基础教程 > python如何判断字符是否大写

python如何判断字符是否大写

头像

爱喝马黛茶的安东尼

2020-01-02 09:44:248562浏览 · 0收藏 · 0评论


例子:

>>> 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

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平台,欢迎关注!

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图