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.

istitle() Syntax

The syntax of istitle() method is:

string.istitle()

istitle() Parameters

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

 istitle() Return value

The istitle() method returns:

  • True if the string is titlecased
  • False if the string is not titlecased 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

Get notified of the best deals on our WordPress themes.

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