扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Python怎么判断字符串是否全为大写或小写字母

扬州沐宇科技
2024-03-02 13:40:30
python

可以使用isupper()islower()方法来判断字符串是否全为大写或小写字母。示例如下:

s = "HELLO"
if s.isupper():
    print("字符串全为大写字母")
else:
    print("字符串不全为大写字母")

s = "hello"
if s.islower():
    print("字符串全为小写字母")
else:
    print("字符串不全为小写字母")

以上代码会输出:

字符串全为大写字母
字符串全为小写字母

扫码添加客服微信