I have a string like this
>>> x="Alpha_beta_Gamma" >>> words = [y for y in x.split('_')] >>> words ['Alpha', 'beta', 'Gamma']
I want output saying X is non conformant as the the second element of the list words starts with a lower case and if the string x = "Alpha_Beta_Gamma"
then it should print string is conformant
isUpperCase(char ch) determines if the specified character is an uppercase character. A character is uppercase if its general category type, provided by Character. getType(ch), is UPPERCASE_LETTER. or it has contributory property Other_Uppercase as defined by the Unicode Standard.
To check if a letter in a string is uppercase or lowercase use the toUpperCase() method to convert the letter to uppercase and compare it to itself. If the comparison returns true , then the letter is uppercase, otherwise it's lowercase. Copied!
To test that all words start with an upper case use this:
print all(word[0].isupper() for word in words)
Maybe you want 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With