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视频教程栏目。
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 模板不会安装或需要功能定制以及二次开发?
发表评论
还没有评论,快来抢沙发吧!