ffg*_*ghh 9 python string python-3.x uppercase toupper
说我有一个字符串.
该字符串可以更改它包含的字符.
例如 word = "UPPER£CASe"
我如何测试字符串以查看字符串中的任何字符是否不是大写的.此字符串必须只包含大写字母,不能包含其他标点符号,数字,小写字母等.
Yas*_*tra 20
你应该使用str.isupper()和str.isalpha()功能.
例如.
is_all_uppercase = word.isupper() and word.isalpha()
Run Code Online (Sandbox Code Playgroud)
根据文件:
Run Code Online (Sandbox Code Playgroud)S.isupper() -> bool返回
True如果所有套管字符S是大写字母,至少有一个在套管字符S,False否则.
您可以使用正则表达式:
all_uppercase = bool(re.match(r'[A-Z]+$', word))
Run Code Online (Sandbox Code Playgroud)