Python capitalize() Method
The No parameters are required. Returns a copy of the string with the first character capitalized and the rest in lowercase. The Python Basic Tutorials
Python Advanced Tutorials
Python capitalize() Method
capitalize() method converts the first character of a string to uppercase and makes all other characters lowercase.Syntax
str.capitalize()Parameters
Returns
Example
#!/usr/bin/python3
str = "hello world"
print("Original string: ", str)
print("Capitalized string: ", str.capitalize())Output
Original string: hello world
Capitalized string: Hello worldExplanation
capitalize() method capitalizes the first letter of the string and converts all other letters to lowercase. If the string is empty or contains only whitespace, it returns an empty string.Additional Notes
See Also
YouTip