Check if all characters of a string are uppercase

前端 未结 5 940
遥遥无期
遥遥无期 2021-01-03 23:21

Say I have a string that can contain different characters:

e.g. word = "UPPER£CASe"

How would I test the string to see if all the charac

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 23:56

    You should use str.isupper() and str.isalpha() function.

    Eg.

    is_all_uppercase = word.isupper() and word.isalpha()
    

    According to the docs:

    S.isupper() -> bool
    

    Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.

提交回复
热议问题