我有这样的字符串
>>> x="Alpha_beta_Gamma" >>> words = [y for y in x.split('_')] >>> words ['Alpha', 'beta', 'Gamma']
我想要输出说X不符合,因为列表单词的第二个元素以小写开头,如果字符串x = "Alpha_Beta_Gamma"则应打印字符串符合
x = "Alpha_Beta_Gamma"
也许你想要 str.istitle
str.istitle
>>> help(str.istitle) Help on method_descriptor: istitle(...) S.istitle() -> bool Return True if S is a titlecased string and there is at least one character in S, i.e. uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return False otherwise. >>> "Alpha_beta_Gamma".istitle() False >>> "Alpha_Beta_Gamma".istitle() True >>> "Alpha_Beta_GAmma".istitle() False