python用函数怎么判断大小写

python用函数怎么判断大小写,第1张

python用函数怎么判断大小写 Python提供了isupper(),islower(),istitle()方法用来判断字符串的大小写, 具体实例如下:

例如:(推荐学习:Python视频教程)

>>> 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教程栏目进行学习!

以上就是python用函数怎么判断大小写的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/681620.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存