Python String istitle() Method
The istitle() method detects whether all words in the string are spelled with the first letter in upper case and the other letters in lower case.
Python String istitle() Syntax
istitle() method syntax.
str.istitle()
Python String istitle() Parameters
- None.
Python String istitle() Return Value
Returns True if the first letter of all words in the string is uppercase and the other letters are lowercase, otherwise returns False.
Python String istitle() Example#1
The following example shows an example of the istitle() method.
#!/usr/bin/python3
s = 'Api Demos'
print(s.istitle())
# First character in first word is lowercase
s = 'api Demos'
print(s.istitle())
s = 'API DemoS'
print(s.istitle())
# Ignore the digit 5555, hence returns True
s = '5555 Is My Number'
print(s.istitle())
# word has uppercase characters at middle
s = 'APIDEMOS'
print(s.istitle())
Output:
Python String istitle() Example#2
Use Python’s String istitle() method to check if a string is case sensitive for a title.
#!/usr/bin/python3
s = 'I Love API Demos'
if s.istitle() == True:
print('Titlecased String')
else:
print('Not a Titlecased String')
s = 'I Love api demos'
if s.istitle() == True:
print('Titlecased String')
else:
print('Not a Titlecased String')
Output: