Python String title() method
Python String title() method
The string.title() method in Python returns a string where the first character in every word is upper case. If the word contains a number or a symbol, the first letter after that will be converted to upper case.
Syntax
string.title()
Parameter
NA
Return
This method returns a string where the first character in every word is upper case.
Example 1
# Python program explaining # the string.tittle() method string="heLLo wORLd" # observe the original string print("Actual String: ",string) # returning the first character in every word is upper case. val = string.title() # printing the titled cased string print("After title() method: ",val)
Output
Actual String: heLLo wORLd After title() method: Hello World
Example 2
# Python program explaining # the string.title() method string1="heLLo wORLd" # observe the original string print ('Original String: ', string1 ) print ('Converted String is = ', string1.title()) # passing special characters string2 = 'mY#namE#Is#REEma#panDA'.title() print ('\nSecond Output for Title() method is = ', string2 ) # passing integer values string3 = '98041'.title() print('\nFourth Output after Title() method is = ', string3 ) string4 = 'pyTHon\niS\neAsy\ntO\nLEARN'.title() print ('\nThird Output after Title() method is = ', string4)
Output
Original String: heLLo wORLd Converted String is = Hello World Second Output for Title() method is = My#Name#Is#Reema#Panda Fourth Output after Title() method is = 98041 Third Output after Title() method is = Python Is Easy To Learn