How to check if a character is upper-case in Python?

前端 未结 7 683
挽巷
挽巷 2020-12-08 09:18

I have a string like this

>>> x=\"Alpha_beta_Gamma\"
>>> words = [y for y in x.split(\'_\')]
>>> words
[\'Alpha\', \'beta\', \'Gam         


        
7条回答
  •  一向
    一向 (楼主)
    2020-12-08 09:28

    words = x.split("_")
    for word in words:
        if word[0] == word[0].upper() and word[1:] == word[1:].lower():
            print word, "is conformant"
        else:
            print word, "is non conformant"
    

提交回复
热议问题