Check if all characters of a string are uppercase

前端 未结 5 965
遥遥无期
遥遥无期 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条回答
  •  梦毁少年i
    2021-01-03 23:57

    Yash Mehrotra has the best answer for that problem, but if you'd also like to know how to check that without the methods, for purely educational reasons:

    import string
    
    def is_all_uppercase(a_str):
        for c in a_str:
            if c not in string.ascii_uppercase:
                return False
        return True
    

提交回复
热议问题