In this tutorial, we’ll learn what Python string title() method is and how to properly use it. We’ll go through multiple Python code examples to understand how title method works.
Outline
- Introduction: Python String title() Method
- Syntax of title() Method
- Example 1: title() Method applied on a Python String
- Example 2: Python String title() Method Return Value
- Conclusion
Introduction: Python String title() Method
This method returns a string after converting the first letter of each word in a string to uppercase format.
Syntax of title() Method
string.title()
- Python string title method does not take any arguments.
- It returns a string after converting the first letter of every word to uppercase in a string.
Example 1: title() Method applied on a Python String
print('this is Python'.title()) print('this is 3_python'.title()) print('this is ^python'.title()) print('This Is Python'.title()) print('this is python'.title())
Output
This Is Python This Is 3_Python This Is ^Python This Is Python This Is Python
We can see in the second and third example that word ‘python’ comes after a number and some special characters but still its first letter is converted to uppercase format. It means the first letter that comes after the number/special characters will also get converted to uppercase format.
This is how Python string title method works. You can try it with even more examples to better understand the working of this method.
Example 2: Python String title() Method Return Value
val='this Is @ 3_$python ___programming' returnedValue=val.title() print(returnedValue)
Output
This Is @ 3_$Python ___Programming
We can see that Python string title method has returned a new string after converting the first letter of every word to uppercase format.
Conclusion
To conclude this tutorial, hope you now have a detailed practical understanding of how to properly use Python string title method. I’d be very happy to receive your feedback on this post. Thank you for reading it.
You may like to read:
How To Properly Use Python String StartsWith Method [Detailed Python Guide]
How To Use Python String IsDecimal() Method – Easy Python Code Guide
How To Easily Use Python String RPartition Method [Detailed Python Guide]
How To Easily Use Python String Split Method [Detailed Python Guide]
How To Properly Use Python String RSplit Method [Detailed Python Guide]
How To Use Python String RStrip Method – Easy Python Code Examples
How To Easily Use Python String RFind Method [Detailed Python Guide]