all Python 3Strings (str)function
str.capitalize
case
Return a copy with the first character capitalized and the rest lowercased.
Syntax
s.capitalize()
Everything after the first character is force-lowercased, so acronyms and internal capitals get mangled: 'HTML file' becomes 'Html file'. To raise just the first letter and leave the rest untouched, uppercase a one-character slice and concatenate the remainder unchanged. Since Python 3.8 the first character is converted to title case rather than upper case — indistinguishable for ordinary letters, different for rare ligatures.
Examples
print('привет МИР'.capitalize()) # → Привет мир
print('123abc'.capitalize()) # → 123abc
print('ALREADY Done'.capitalize()) # → Already done
See also
Open in the full glossarydocs.python.orgReport an inaccuracy