Skip to main content

title()

The title() method in Python is a string method that returns a copy of the string with the first character of each word. First character are converted to uppercase and all other characters converted to lowercase. This is useful for formatting strings where each word should start with an uppercase letter.

Parameter Values

This function does not accept any parameters.

Return Values

The title() method from String Methods returns a new string.

How to Use title() in Python

Example 1:

The title() method returns a copy of the string with the first character of each word capitalized and all other characters in lowercase.

text = 'hello world'
print(text.title())
Example 2:

If the string already contains capitalized words, the title() method will lowercase the non-initial characters.

title = 'Hello WORLD'
print(title.title())
Example 3:

Numbers and special characters are not affected by the title() method, only alphabetic characters are capitalized at the beginning of words.

sentence = 'python3 is fun!'
print(sentence.title())