The istitle() method is a built-in method in Python that belongs to the string data type. It is used to check whether a string is titlecased or not.
In Python, a string is considered titlecased if it meets the following conditions:
1. The first character of each word in the string is capitalized.
2. All other characters in the word are in lowercase.
The istitle() method returns True if the string satisfies these conditions, and False otherwise.
Syntax:
string.istitle()
How to use the istitle() method:
string1 = "This Is Titlecased"
print(string1.istitle()) # Output: True
string2 = "This is not Titlecased"
print(string2.istitle()) # Output: False
Example 2
Filtering Titlecased Words.
words = ["Apple", "banana", "Carrot", "date"]
titlecased_words = [word for word in words if word.istitle()]
print(titlecased_words) # Output: ['Apple', 'Carrot']