Python String title()

The Python String title() method is a built-in function that returns a string where the first character of each word is uppercase. It is also called a title case string.

Syntax

The Syntax of title() method is:

str.title()

Parameters

The title() method does not take any parameters.

Return Value

The title() method returns the title cased version of a string. The first character of each word in a string is capitalized.

Note: The first letter is capitalized if it's a valid letter. In the case of digits or numbers, the conversion to uppercase will not happen.

Example 1: How Python title() function work

text = "Welcome to python programming, itsmycode"
print(text.title())

text = "5 times 4 is = to 20 "
print(text.title())

Output

Welcome To Python Programming, Itsmycode
5 Times 4 Is = To 20 

Example 2: title() method in case of numbers and apostrophes in the string

The presence of digits or numbers before the word will not affect the working of the function. The character after the digit is considered as the first character.

In the case of apostrophes, the title() method capitalizes the first letter and the letter after the apostrophes as well.

# incase the of numbers or digits at the beginning
text = "20dollars is the cost of Python programming book"
print(text.title())

# in case of apostrophes
text = "it's python's interpreter"
print(text.title())

Output

20Dollars Is The Cost Of Python Programming Book
It'S Python'S Interpreter
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