What is String title() Method?
String title() is an in-built function in Python that is used to change text in title format. It converts the first letter of every word to uppercase and other letters to lowercase and then returns this new string.
It is very useful function for string formatting. You can easily format texts for page titles or headings.
Note: Any non-alphabetic character is considered as the start of a new word in the title function, for example it will turn “do’s” to “Do’S”.
How to Use String title() Function
String title() function is a very easy string method. You just need to call the function with object string. Let’s look at how to convert a string to title with an example:
Python3
# using string title function print ( "cOnverting to TiTle" .title()) |
Output
Converting To Title
Python String Title method
Python String title() method returns a new string after converting the first letter of every word to uppercase(capital) and keeping the rest of the letters lowercase.
Example: Make string title case
Python3
print ( "usE stRing title Method" .title()) |
Output
Use String Title Method