The title() function in python helps to return a new string in which the first character of each word should be a capital letter and the remaining will be small letters like a header or title.
str.title()
The title() method doesn't take any parameters. The conversion will perform only if the first character of the word is a letter. If the word starts with a number or a symbol the first letter after this will be capitalized.
The return value will be a copy of the original string. The title() capitalizes the first character after apostrophes also.
Input | Return Value |
---|---|
string | title cased string |
string1 = 'my name is jhon 25.'
print(string1.title())
string2 = '45 nm44 *67 find'
print(string2.title())
Output:
My Name Is Jhon 25 45 Nm44 *67 Find
string = "she's a docter, isn't she?"
print(string.title())
Output:
She'S A Docter, Isn'T She?