The Python title function is used to convert the first character in each word to Uppercase and the following characters to Lowercase and returns a new string. This section discusses how to write the title Function with an example.
The Python string title Function keeps the Non-letters unchanged, and its syntax is
Python title function Example
The following set of examples helps you understand the string title Function. For str2, it converts the above text into a title case and prints the output.
The title function returns the output in a new string instead of altering the original. We show the same using the next two print functions.
From the below image, see that the original Str1 is unchanged. If you want to change the original, write the following Python statement.
Str1 = Str1.title()
The Python title string function only converts the first letter of each word into Uppercase. And convert the following words into lowercase, but it leaves other values unchanged.
Within the following Str4 and Str5 statements, we used numeric values and letters. And you can see the String Method output for further reference.
Str1 = 'learn PYTHON AT tutOrial gateWay' Str2 = Str1.title() print('First Output is = ', Str2) # Observe the Original String print('Converted String is = ', Str1.title()) print('Original String is = ', Str1) # Performing directly Str3 = 'pYTHON proGramminG'.title() print('Second Output after method is = ', Str3) Str4 = 'pyTHon 1234 tuTorIal'.title() print('Third Output is = ', Str4) Str5 = '12345'.title() print('Fourth Output is = ', Str5)