Python提供了isupper(),islower(),istitle()方法用来判断字符串的大小写, 具体实例如下:
例如:(推荐学习:Python视频教程)
复制代码1
2
3
4
>>> str_1 = "HELLO PYTHON" # 全大写
>>> str_2 = "Hello PYTHON" # 大小写混合
>>> str_3 = "Hello Python" # 单词首字母大写
>>> str_4 = "hello python" # 全小写
登录后复制
isupper() 判断是否全是大写
复制代码1
2
3
4
5
6
7
8
>>> str_1.isupper()
True
>>> str_2.isupper()
False
>>> str_3.isupper()
False
>>> str_4.isupper()
False
登录后复制
islower()判断是否全是小写
复制代码1
2
3
4
5
6
7
8
>>> str_1.islower()
False
>>> str_2.islower()
False
>>> str_3.islower()
False
>>> str_4.islower()
True
登录后复制
istitle()判断首字母是否大写, 其余的是否小写
复制代码1
2
3
4
5
6
7
8
>>> str_1.istitle()
False
>>> str_2.istitle()
False
>>> str_3.istitle()
True
>>> str_4.istitle()
False
登录后复制
最后
以上就是迷你外套最近收集整理的关于python用函数怎么判断大小写的全部内容,更多相关python用函数怎么判断大小写内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复