What is the capitalize() Method in Python?
The capitalize() method in Python is a built-in string function that converts the first character of a string to uppercase and changes all remaining characters to lowercase.
This method is particularly useful when formatting titles, names, or sentences, ensuring that the text follows a clean and standardized structure. Whether you’re cleaning user inputs, normalizing data, or preparing text for display — capitalize() helps make strings look more professional.
Purpose of the capitalize() Method
The main purpose of capitalize() is to standardize text formatting by:
- Converting the first character of a string to uppercase
- Making all other characters lowercase
This ensures consistent styling for data such as names (“john” → “John”) or titles (“python programming” → “Python programming”).
Syntax of capitalize()
string.capitalize()
Example: How capitalize() Works
text = "python is awesome!"
result = text.capitalize()
print(result)
# Output:Python is awesome!
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.