Python String Title Method

In python, the string title() method is useful to convert the first letter of every word in the given string to uppercase. If the first letter of the word is a number or symbol, it will convert the next letter to uppercase.

 

Following is the pictorial representation of the string title() method functionality in python.

 

Python string title method example result

 

If you observe the above diagram, we are trying to convert the given string “hi guest hi” to title case using the title function in python.

String Title Method Syntax

Following is the syntax of defining a string title method in python.

 

string.title()

The python title() method will not accept any parameters.

String Title Method Example

Following is the example of converting the first letter of every word in the given string to uppercase using the string title() method in python.

 

msg1 = "hi guest hi"
print(msg1.title())
msg2 = "welcome to 2tutlane"
print(msg2.title())
msg3 = "3#learn python"
print(msg3.title())

If you observe the above example, we are converting the first letter of every word in the given string to uppercase using the title() method.

 

When you execute the above python program, you will get the result as shown below.

 

Hi Guest Hi
Welcome To 2Tutlane
3#Learn Python

This is how you can use the string title() method in python to convert the given strings to title case based on your requirements.