用python如何判断字符的大小写
发布时间:2026-05-29 09:56:42

Python提供isupper(),islower(),istitle()该方法用于判断字符串的大小写。
1、isupper()方法
Python isupper() 检测字符串中的所有字母是否都是大写的方法。
示例:
str="THISISSTRINGEXAMPLE...WOW!!!"; printstr.isupper(); str="THISisstringexample...wow!!!"; printstr.isupper();
输出如下:
TrueFalse
2、islower()方法
Python islower() 检测字符串是否由小写字母组成。
islower()方法语法:str.islower()
示例:
str="THISisstringexample...wow!!!"; printstr.islower(); str="thisisstringexample...wow!!!"; printstr.islower();
输出如下:
FalseTrue
3、istitle()方法
Python istitle() 检测字符串中所有单词拼写首字母是否为大写,其他字母为小写。
istitle()方法语法:str.istitle()
示例:
str="ThisIsStringExample...Wow!!!"; printstr.istitle(); str="Thisisstringexample...wow!!!"; printstr.istitle();
输出如下:
TrueFalse
请关注Python视频教程栏目,了解更多Python知识。
下一篇 怎样用python计算矩阵乘法?
