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

PythonServer Side ProgrammingProgramming

To be precise, above string four words starting with uppercase character. This, Delhi, City and India.

Two string functions should be used for this purpose. 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.

Following code lists words starting with capital letters.

s1="This is not true that Delhi is the hottest or coldest City in India"
for word in s1.split():
    if word[0].isupper():
        print (word)

The output is:

This
Delhi
City
India
raja
Published on 01-May-2018 00:32:24
Advertisements