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

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

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

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

以上代码会输出:

字符串全为大写字母
字符串全为小写字母
阅读剩余
THE END