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
s'
is in title case because the first letter of each word is uppercase, and the rest of the letters are lowercase.True
, confirming that the string adheres to the title case format.Parameters
string.istitle()
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
's'
and confirms it follows title case.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
'
does not adhere to title case because the first word, "python," starts with a lowercase letter.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
Let's what happens if we pass an empty string to istitle().
Python
s = ""
# Checking an empty string
res = s.istitle()
print(res)
Explanation
False
.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
True
.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4