How to convert the first character of each word of a string to uppercase in Python

Conversion of First Character of Each Word of a String to Uppercase in Python

In Python, you can convert the first character of each word of a string to uppercase using the str.title() method.

Converting the first character of each word of a string to uppercase using 'str.title()' method

1. Create a variable named str_variable and assign string value "python iS A proPramming language." to the variable.

2. Apply the title() method to the string variable str_variable. This method converts the first character of each word of a string to uppercase. Store the result in a new variable called title_string and get the output using print() function.

Please take a closer look at the following example:

Example of using title() method

Output of the above example
Python Is A Programming Language.

Live Code Playground

In the following Python code editor, you can practice the above code by creating more string variables and converting the first character of each word of the strings using str.title() method. Click on the 'Execute Code' button to execute the code; the executed output will be displayed in the following Python Code Output frame. Practice until you become comfortable and proficient with your code.

Python logo Python Online Editor
Python Code Output