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 string title Function keeps the Non-letters unchanged, and its syntax is
Python title method 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, then you can write the following Python statement.
Str1 = Str1.title()
The 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 the numeric values along with 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)