重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

用python判断字符大小写的方法

小编给大家分享一下用python判断字符大小写的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

成都创新互联提供高防服务器、云服务器、香港服务器、服务器托管

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判断字符大小写的方法
文章转载:http://cqcxhl.cn/article/jjgpos.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP