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
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())
If the string already contains capitalized words, the title()
method will lowercase the non-initial characters.
title = 'Hello WORLD'
print(title.title())
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())