用python如何判断字符的大小写

2025-12-01 0 78,646

Python提供了isupper(),islower(),istitle()方法用来判断字符串的大小写。

1、isupper()方法

Python isupper() 方法检测字符串中所有的字母是否都为大写。

示例:

str = "THIS IS STRING EXAMPLE....WOW!!!"; 
print str.isupper();

str = "THIS is string example....wow!!!";
print str.isupper();

输出如下:

True
False

2、islower()方法

Python islower() 方法检测字符串是否由小写字母组成。

islower()方法语法:str.islower()

示例:

str = "THIS is string example....wow!!!"; 
print str.islower();

str = "this is string example....wow!!!";
print str.islower();

输出如下:

False
True

3、istitle()方法

Python istitle() 方法检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写。

istitle()方法语法:str.istitle()

示例:

str = "This Is String Example...Wow!!!";
print str.istitle();

str = "This is string example....wow!!!";
print str.istitle();

输出如下:

True
False

更多Python知识请关注Python视频教程栏目。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 python基础 用python如何判断字符的大小写 https://www.zhiup.top/5249.html

相关