用python如何判断字符的大小写

图片[1]-用python如何判断字符的大小写-uusu优素-乐高,模型,3d打印,编程

Python提供了isupper(),islower(),istitle()方法用来判断字符串的大小写。

1、isupper()方法

Python isupper() 方法检测字符串中所有的字母是否都为大写。

示例:

str="THISISSTRINGEXAMPLE....WOW!!!";
printstr.isupper();
str="THISisstringexample....wow!!!";
printstr.isupper();

输出如下:

True
False

2、islower()方法

Python islower() 方法检测字符串是否由小写字母组成。

islower()方法语法:str.islower()

示例:

str="THISisstringexample....wow!!!";
printstr.islower();
str="thisisstringexample....wow!!!";
printstr.islower();

输出如下:

False
True

3、istitle()方法

Python istitle() 方法检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写。

istitle()方法语法:str.istitle()

示例:

str="ThisIsStringExample...Wow!!!";
printstr.istitle();
str="Thisisstringexample....wow!!!";
printstr.istitle();

输出如下:

True
False

原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容