This is a tutorial of the Python String istitle() method. Learn to check if a given string is in Title Case or not with the help of illustrative examples.
str.istitle() method returns True either if the given string is in Title Case and if not it returns False.
Note. A String in which the first character of all the words is in Uppercase is known as a Title Cased String.
Given below is the syntax of the
ifInTitleCase = givenString.istitle()
This method does not take any arguments as it only checks the given string on which it is applied, so no additional data is required in the form of arguments.
istitle() Return Value
It returns the boolean value
False according to the following logic.
Trueif the given string is in Title Case.
Falseif not the given string is not in Title Case.
Given below are the two examples demonstrating the usage of the Python String
Example 1. Checking if a given String is in Title Case or not using
In this example, we’re applying the method
istitle() on several different strings to check the result, for what strings it returns
True and for what it returns
#lowercase string line = "this string is in lowercase" print(line.istitle()) #uppercase string line = "THIS STRING IS IN UPPERCASE" print(line.istitle()) #alternate case line = "ThIs sTrInG Is iN AlTeRnAtE CaSe" print(line.istitle()) #Title Case line ="This String Is In Title Case" print(line.istitle())
False False False True
Example 2. Using the Python String
istitle() method with if-else statement
In the following example, we’ve directly used the
str.istitle() method as the condition for the if-else statement to print a string accordingly after checking if the given string is in Title Case or not.
#Using str.istitle() with if-else statement #Given String name = "Gurmeet Singh" if name.istitle(): print("name is in Title Case.") else: print("name is not in Title Case.")
name is in Title Case.
I hope you found this guide useful. If so, do share it with others who are willing to learn Python and other programming languages. If you have any questions related to this article, feel free to ask us in the comments section.
And do not forget to subscribe to WTMatter!