python中islower()、isupper()、istitle()函数的用法详解

一、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
  • 7
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值