Python String istitle()

Python String istitle() is used to check if given string follows the rules of a title. A string is said to be a title if all the words in this string start with an uppercase, and the rest of the characters are lowercase.

istitle() method returns True if the string is a title, or else the method returns False.

In this tutorial, we will learn the syntax and examples for istitle() method of String class.

Syntax

The syntax to call istitle() method on string x in Python is

</>
Copy
x.istitle()

Examples

In the following program, we take a string 'Python Tutorial By Tutorialkart' in x, and check if this string x is a title using istitle() method.

Example.py

</>
Copy
x = 'Python Tutorial By Tutorialkart'
result = x.istitle()
print(result)

Output

True

In the following program, we take a string 'Python Tutorial by Tutorialkart' in x, and check if this string x is a title using istitle() method. Since, the third word by in this string starts with a lower case, this string is not a title and the method returns False.

Example.py

</>
Copy
x = 'Python Tutorial by Tutorialkart'
result = x.istitle()
print(result)

Output

False

Conclusion

In this Python Tutorial, we learned how to check if given string is a title or not, using String method – istitle().