Python title

The Python title function is used to convert the first character in each word to Uppercase and following characters to Lowercase and return a new string. In this section, we discuss how to write title Function in Python Programming with example.

The string title Function keeps the Non-letters unchanged. The syntax of the title function in Python Programming Language is

String_Value.title()

String_Value: Please select a valid String variable, or you can use the String directly.

Python title method Example

The following set of examples help you understand the string title Function.

# Python Title() Method Example

Str1 = 'learn PYTHON AT tutOrial gateWay'
Str2 = Str1.title()
print('First Output after Title() method is = ', Str2)

# Observe the Original String
print('Converted String is = ', Str1.title())
print('Original String is = ', Str1)

# Performing title() function directly
Str3 = 'pYTHON proGramminG'.title()
print('Second Output after Title() method is = ', Str3)

Str4 = 'pyTHon 1234 tuTorIal'.title()
print('Third Output after Title() method is = ', Str4)

Str5 = '12345'.title()
print('Fourth Output after Title() method is = ', Str5)
Python Title

First, we declared the String variable Str1 and assigned the following statement

Str1 = 'learn PYTHON AT tutOrial gateWay'

It converts the above string into title case using title function and prints the output.

Str2 = Str1.title()
print('First Output after Title() method is = ', Str2)

The string title function in Python returns the output in a new string instead of altering the original string.

print('Converted String is = ', Str1.title())
print('Original String is = ', Str1)

See that the original string Str1 is unchanged. If you want to change the original String, then you can write the following Python statement

Str1 = Str1.title()

The string titlecase function in Python 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 statements, we used the numeric values along with letters, and you can see the String Method output for further reference.

Str4 = 'pyTHon 1234 tuTorIal'.title()
print('Third Output after Title() method is = ', Str4)

Str5 = '12345'.title()
print('Fourth Output after Title() method is = ', Str5)