In this tutorial, We will see the python string title() method with examples.
title() Method
The title() method is one of the methods in a python string. The title() method is used for string conversion.
- The title() method converts the string first character of every word to uppercase and the rest of the characters to lowercase.
- If the first character of all words in the string is already in uppercase and the rest are in lower case, then applying the title() method will not bring any change.
Syntax of Python string title() method
This is the syntax of the python string title() method.
string.title()
Example of Python string title() method
#Example 1 text = "PYTHON IS A PROGRAMMING LANGUAGE" print(text.title()) #output : Python Is A Programming Language
#Example 2 text = "python title() method" print(text.title()) #output: Python Title() Method #Exmaple 3 message = "hello WORLD!" msg = message.title() print(msg) #output: Hello World!
Program: Take a string from the user and convert it into a title case.
message = input("Enter the message") msg = message.title() print(msg)
Related Posts