一、python判断字符串大小写
string.islower() 判断字符串的区分大小写的字符是否全为小写。
string.isupper() 判断字符串的的字符是否全为大写。
string.istitel() 判断字符串的的所有单词是否首字母(开头)是大写其他为小写。
1.islower()函数
判断字符串的区分大小写的字符是否全为小写。
>>> a="abcd123" #判断数字和字母 True
>>> a.islower()
True
>>> a="abcd" #True
>>> a.islower()
True
>>> a="abCD" #判断字母大小写 False
>>> a.islower()
False
>>> a="abc%&*" #判断字符和特殊符号 True
>>> a.islower()
True
>>>
2.isupper()函数
判断字符串的的字符是否全为大写
>>> a="abcd123" #False
>>> a.isupper()
False
>>> a="AbCD" #False
>>> a.isupper()
False
>>> a="Abcd" #False
>>> a.isupper()
False
>>> a="ASDFG" #True
>>> a.isupper()
True
>>> a="ABC%&*" #True
>>> a.isupper()
True
>>>
3.istitel()函数
判断字符串的的所有单词是否首字母(开头)是大写其他为小写。
>>> a="abcd" #False
>>> a.istitle()
False
>>> a="Abcd" #True
>>> a.istitle()
True
>>> a="ABC%&*" #False
>>> a.istitle()
False
>>> a="Abcd123" #True
>>> a.istitle()
True
>>> a="I Love China!" #标准的首字母大写,结尾还有特殊字符
>>> a.istitle()
True