The istitle() function in python helps to check whether the string is titlecased or not. If yes it returns True else it returns False. Here the word titlecased means each word's first character is upper case letter and remaining in the word are in lower case.
string.istitle()
The istitle() method doesn't take any parameters. In checking with the string, all symbols and numbers are ignored.
The return value is always a boolean value. In case of an empty string, numeric string, or a string with only symbols the function will return False.
Input | Return Value |
---|---|
titlecased string | True |
not a titlecased string | False |
string = 'Hi How Are You'
print(string.istitle())
string = 'Hi how are you'
print(string.istitle())
string = 'Hi How Are You?'
print(string.istitle())
string = '121 Hi How Are You'
print(string.istitle())
string = 'HOW ARE YOU'
print(string.istitle())
Output:
True False True True False
string = 'Python programming'
if string.istitle() == True:
print('It is a Titlecased String')
else:
print('It is not a Titlecased String')
string = 'PYthon PRogramming'
if string.istitle() == True:
print('It is a Titlecased String')
else:
print('It is not a Titlecased String')
Output:
It is a Titlecased String It is not a Titlecased String