Python string istitle() method is a built-in function that returns True if the string is a title case. Otherwise, it returns false.
What is titlecase?
A title case is a capitalization style used for titles where the first letter of each word is in uppercase, and the remaining letter is in lowercase.
Syntax
The syntax of istitle()
method is:
string.istitle()
Parameters
The istitle()
method doesn’t take any parameters.
Return value
The istitle()
method returns:
True
if the string is title casedFalse
if the string is not title cased or empty string
Example 1: Python string istitle() working examples
# Title case string
text1 = "Python Tutorials"
print(text1.istitle())
# First character is lowercase
# Non titlecase
text2= "hello World"
print(text2.istitle())
# one word title case
text3= "Itsmycode"
print(text3.istitle())
# Empty string non titlecase
text4=""
print(text4.istitle())
# Both the words has uppercase
#in the middle
text5= "PythoN TutoriALS"
print(text5.istitle())
#title case string
text6="123 Is Number"
print(text6.istitle())
Output
True
False
True
False
False
True
Example 2: Program to check if the string is titlecase
# Title case string
text1 = "Python Tutorials"
if(text1.istitle()):
print("String is titlecase")
else:
print("String is not titlecase")
# First character is lowercase
# Non titlecase
text2= "hello World"
if(text2.istitle()):
print("String is titlecase")
else:
print("String is not titlecase")
Output
String is titlecase
String is not titlecase