教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 python怎么判断大小写

python怎么判断大小写

发布时间:2021-04-20   编辑:jiaochengji.com
教程集为您提供python怎么判断大小写等资源,欢迎您收藏本站,我们将为您提供最新的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

相关推荐:《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中if有多个条件怎么办
python判断字符类型怎么做
python循环语句怎么写
python如何判断字符是否大写
python if中else结构语句如何用?
python怎么判断字符串以什么结尾

[关闭]
~ ~