Python String istitle() Method is used to verify the input string title condition, i.e., it tests and returns True if the only first character of each word is uppercase, and all other characters of each word are in lowercase.
The syntax of the method is: str.istitle()
Key Points :
• Return Type: Boolean i.e. True or False
• Parametric Values: There are no istitle() function parameters.
• The istitle() function does not take into consideration symbols and numbers in a specified string.
• Those strings having the first letter in uppercase and the rest in lowercase for all the words in it are said to be in title cased. Therefore, if a string is in the titlecase, this function returns the true returns false otherwise.
We’ll be covering the following topics in this tutorial:
Return Value from istitle()
The istitle() method returns:
• True if the string is a titlecased string.
• False if the string is not a titlecased string or an empty string.
Below is the python program to demonstrate the istitle() function:
str = "The Best Learning Resource For Online Education"; print (str.istitle()) str = "The Best Learning Resource for Online Education"; print (str.istitle())
When we run above the program, the outcome is as follows:
True
False
How to use istitle()?
str = 'The Best Learning Resource' if str.istitle() == True: print('Titlecased String') else: print('Not a Titlecased String') str = 'Learning Resource for ONLINE EDUCATION' if str.istitle() == True: print('Titlecased String') else: print('Not a Titlecased String')
When we run above the program, the outcome is as follows:
Titlecased String
Not a Titlecased String
Below are several other functions that we can use to work with string in Python 3