Python String istitle()

Python string istitle() method is a built-in function that returns True if the string is a title case. Otherwise, it returns false.

What is titlecase?

 A title case is a capitalization style used for titles where the first letter of each word is in uppercase, and the remaining letter is in lowercase.

Syntax

The syntax of istitle() method is:

string.istitle()

Parameters

The istitle() method doesn’t take any parameters.

Return value

The istitle() method returns:

  • True if the string is title cased
  • False if the string is not title cased or empty string

Example 1: Python string istitle() working examples

# Title case string
text1 = "Python Tutorials"
print(text1.istitle())

# First character is lowercase
# Non titlecase
text2= "hello World"
print(text2.istitle())

# one word title case
text3= "Itsmycode"
print(text3.istitle())

# Empty string non titlecase
text4=""
print(text4.istitle())

# Both the words has uppercase
#in the middle
text5= "PythoN TutoriALS"
print(text5.istitle())

#title case string
text6="123 Is Number"
print(text6.istitle())

Output

True
False
True
False
False
True

Example 2: Program to check if the string is titlecase

# Title case string
text1 = "Python Tutorials"
if(text1.istitle()):
    print("String is titlecase")
else:
    print("String is not titlecase")

# First character is lowercase
# Non titlecase
text2= "hello World"
if(text2.istitle()):
    print("String is titlecase")
else:
    print("String is not titlecase")

Output

String is titlecase
String is not titlecase
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like
List Of Python Free Ebooks

List of Free Python Books

Table of Contents Hide Python SuccinctlyPython Data Science HandbookThink Python 2nd EditionAutomate the Boring Stuff with PythonMaking Games with Python & PygameData Structures and Algorithms in Python Google Python Style GuideA…
View Post