导语:
本文主要介绍了关于用python如何判断字符的大小写的相关知识,包括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中减去两个数字08/28
- ♥ 2020学python好还是php好?01/09
- ♥ 如何在 PyThon numpy 中将数组转换为列表?10/05
- ♥ 使用 __slots__ 在 python 中定义类属性11/23
- ♥ Python如何判断一个数是否为整数?08/18
- ♥ python可以开发网站吗?09/20
内容反馈