String Methods
capitalize()
Return a copy with the first character uppercase and the rest lowercase.
str.capitalize()
str.capitalize() returns a copy of the string with its first character converted to uppercase and all other cased characters converted to lowercase.
Non-alphabetical leading characters (such as digits or symbols) remain unchanged while the rest of the string is still lowercased.
Result
Returns
A new string with its first character capitalised and remaining cased characters lowercased.
Run it
Try it
Run it and change it
text = "hELLO world" print(text.capitalize())
Output
Press Run to see what it prints.Worth knowing
- Only first character uppercase: Unlike
title(), which capitalizes every word,capitalize()only capitalizes the very first letter of the entire string.