Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test if a string starts with a capital letter? [duplicate]

Tags:

python

string

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.

like image 398
mix Avatar asked Sep 24 '13 06:09

mix


People also ask

How would you check if each word in a string begins with a capital letter?

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.

How can I test if a string starts with a capital letter using Java?

The java. lang. Character. isUpperCase(char ch) determines if the specified character is an uppercase character.

How do you know if a word starts with a capital letter in Python?

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.


1 Answers

In [48]: x = 'Linux'
In [49]: x[0].isupper()
Out[49]: True
In [51]: x = 'lINUX'
In [53]: x[0].isupper()
Out[53]: False
like image 166
KillianDS Avatar answered Oct 22 '22 17:10

KillianDS