Python string Method - istitle()
The istitle()
method is a built-in string method in Python that returns True
if the string is a titlecased string, that is, if the string is composed of words that start with an uppercase character followed by lowercase characters, and all other characters in the words are lowercase. Otherwise, it returns False
.
Here is the syntax of the istitle()
method:
str.istitle()
The istitle()
method does not take any arguments. It can be called on a string and returns a Boolean value.
Example:
# Example 1 string1 = "This Is A Titlecased String" print(string1.istitle()) # Output: True # Example 2 string2 = "This is not a Titlecased String" print(string2.istitle()) # Output: False
In the above example, string1
is a titlecased string because each word starts with an uppercase letter and all other characters in the words are lowercase, so istitle()
method returns True
. string2
is not a titlecased string because not all the words start with an uppercase letter, so istitle()
method returns False
.