Python String – title() method

It is a method in python that returns all the first character of every word in upper case of a string. If a word contains any special character or number the following letter is converted to upper case.

Syntax:

string.title()

Example 1:

s = “title is a method in python
x = s.title()
print(x)

Output:

Title Is A Method In Python

Explanation:

Here the first letter of all the words are converted to upper case. Since there is has a space before all the word excluding the first word.


*Have a closer attention to the next example!

Example 2:

s = “title i!s a method in python
x = s.title()
print(x)

Output:

Title I!S A Method In Python

Explanation:

Here the letter “S” is converted to upper case since the previous character is a special character (!) along with first character of all the words in the string.

You Missed