How Can We Help?
In this tutorial, we will explain how to use Python string capitalize() method with basic syntax by example for better understanding.
How to capitalize string in Python? To capitalize a string in Python, we use the String capitalize() method. The capitalize method in Python capitalizes the first character of the first word of a given String.
Syntax:
<string_value/string_variable>.capitalize()
Input Parameters:
- string_value / String variable : The string that we want to convert to the capitalize it.
Example
msg= 'welcome to python with Oraask'
print('Capital: ',msg.capitalize())
Output of example
Title : Welcome to python with oraask
In the above example, the first word of the string variable ‘msg’ is title cased by msg.capitalize() and the output shows as ‘ Welcome to python with oraask’.
In this tutorial, you have learned the string capitalize() method in Python. And how to Capitalize the first character of the first word for a given string.
Hopefully, it was clear and concise.
If you have an inquiry or doubt, don’t hesitate to leave them in a comment. We are waiting for your valuable feedback.
Similar Python Formatting Methods:
- title() : It returns the “title cased” version of string means all the words start with uppercase and the remaining are lowercase.
- center() : It returns a space-padded string with the original string centered to a total of width columns.
- swapcase() : It inverts the case of all the characters in a string.
- lower() : It converts all the characters of a string to lowercase.
- upper() : It converts all the characters of a string to uppercase.
- rstrip() : It removes particular character of a string from right side.
- lstrip() : It removes particular character of a string from left side.
- strip(chars) : It removes particular characters of a string from left and right side.
- ljust() : It returns an original string with a filled specific character or space at the left side of the string value to justify the string’s new length (width).
- rjust() : It returns an original string with a filled specific character or space at the right side of the string value to justify the string’s new length (width).
- zfill() : It returns an original string value with filled zero at the left side of the string value to justify the string’s new length (width).
Related Articles
Python String – Mastering By Practical Examples (Comprehensive Guide)
Python Tutorials List:
- Python tutorials list : access all python tutorials.