Given any string in Python, how can I test to see if its first letter is a capital letter? For example, given these strings:
January
dog
bread
Linux
table
I want to be able to determine that January
, and Linux
are capitalized.
Assuming that words in the string are separated by single space character, split() function gives list of words. Secondly to check if first character of each word is uppercase, use isupper() function.
The java. lang. Character. isUpperCase(char ch) determines if the specified character is an uppercase character.
Python Isupper() To check if a string is in uppercase, we can use the isupper() method. isupper() checks whether every case-based character in a string is in uppercase, and returns a True or False value depending on the outcome.
In [48]: x = 'Linux'
In [49]: x[0].isupper()
Out[49]: True
In [51]: x = 'lINUX'
In [53]: x[0].isupper()
Out[53]: 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