我是靠谱客的博主 迷你外套,这篇文章主要介绍python用函数怎么判断大小写,现在分享给大家,希望可以做个参考。

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用函数怎么判断大小写内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(85)

评论列表共有 0 条评论

立即
投稿
返回
顶部