Python 3 reference · String Methods
Python String capitalize() Method
Return a copy of the string with the first character in upper case and the rest in lower case.
Python 3 Since 3.0
Syntax
str.capitalize()
Return value
A new string.
Examples
print("hello WORLD".capitalize())
Output
Hello world
print("élan".capitalize(), "123abc".capitalize())
Output
Élan 123abc
Good to know
capitalize() lower-cases everything after the first character. To upper-case the first letter of every word,
use title(); to change only the first character, use s[:1].upper() + s[1:].
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.title()· Return a title-cased copy: the first letter of each word upper case and the rest lower case.str.upper()· Return a copy of the string with all cased characters converted to upper case.str.lower()· Return a copy of the string with all cased characters converted to lower case.- Python Strings · tutorial