The capitalize()
method in Python is a String Method that capitalizes the first letter of a string and makes all other characters lowercase. It returns a new string with the modified formatting.
Parameter Values
This function does not accept any parameters.Return Values
The capitalize()
method returns a new string with the first character capitalized.
How to Use capitalize()
in Python
Example 1:
The capitalize()
method returns a copy of the string with the first character capitalized and the rest lowercase.
'hello world'.capitalize()
Example 2:
If the first character is already capitalized, the method will return the unchanged string.
'Hello'.capitalize()
Example 3:
Special characters, numbers, and symbols are not affected by the method and remain unchanged.
'123abc'.capitalize()