Python String istitle() Method (original) (raw)

Last Updated : 05 Jan, 2025

The istitle() method in Python is used to check whether a string follows the title case formatting. In a title-cased string, the first letter of each word is capitalized, and all other letters in the word are in lowercase. This method is especially useful when working with formatted text such as titles, headlines, or document headers.

Let’s understand with the help of an example:

Python `

s = "Python is Fun"

Checking if the string is in title case

res = s.istitle() print(res)

`

Explanation

Syntax of istitle() Method

string.istitle()

Parameters

Return Type

Examples of istitle() method

1. Checking a proper title-case string

Here, we test the istitle() method with a correctly formatted title-case string to verify its behavior.

Python `

s = "Python Programming"

Verifying if the string is in title case

result = s.istitle() print(result)

`

Explanation

2. String with improper casing

In this example, we analyze a string that does not conform to title case rules. This helps illustrate how istitle() handles such cases.

Python `

s = "python Programming"

Verifying if the string is in title case

res = s.istitle() print(res)

`

Explanation

3. Strings with special characters and numbers

This example demonstrates how istitle() behaves when the string contains special characters or numbers. These elements do not affect the title case evaluation.

Python `

s = "Python 3.9 Is Awesome"

Checking title case for a string with numbers and special characters

result = s.istitle() print(result)

`

Explanation

4. Empty string

Let’s what happens if we pass an empty string to istitle().

Python `

s = ""

Checking an empty string

res = s.istitle() print(res)

`

**Explanation

5. Mixed cases with acronyms

Here, we examine a string containing an acronym to understand how istitle() processes such cases.

Python `

s = "NASA Is Amazing"

Verifying a string with an acronym

res = s.istitle() print(res)

`

Explanation