python怎么判断大小写

1,567次阅读
没有评论

python怎么判断大小写

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

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
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-06-24发表,共计538字。
新手QQ群:570568346,欢迎进群讨论 Python51学习