String method

str.capitalize()

Returns a copy of a string with its first character in capitals and all the other letters turned into small letters.

BeginnerEvery example below runs in your browser. Change the code and press Run.

str.capitalize()

capitalize() makes the first character of the string a capital and every other letter small: "hELLO wORLD" becomes "Hello world".

Use it to tidy a single word or the start of a sentence, such as a name typed in the wrong case.

Note the second half of the rule: it does not just raise the first letter, it also lowers all the others. "iPhone" or "NASA rocket" lose their capitals. If the string starts with a space or digit, nothing becomes a capital.

Return value

A new string with only the first character in capitals.

Examples

1Capitalise a word

Pythoneditable
print("python".capitalize())
print("hELLO wORLD".capitalize())
Output
Python
Hello world

2Tidy a list of first names

Pythoneditable
names = ["ana", "OMAR", "yUKI"]
print([n.capitalize() for n in names])
Output
['Ana', 'Omar', 'Yuki']

3The rest of the string gets lower-cased

Pythoneditable
print("NASA launches a rocket".capitalize())
Output
Nasa launches a rocket

To raise only the first letter and keep the rest, use s[:1].upper() + s[1:].

4Capitalise the first letter only

Pythoneditable
s = "nASA launches a rocket"
print(s[:1].upper() + s[1:])
print(" 2 apples".capitalize())
Output
NASA launches a rocket
 2 apples

A string starting with a space or digit has no letter to raise.

Common mistakes

Using capitalize() for every word

It only affects the first character of the whole string. For each word, use title() or string.capwords().

Pythoneditable
city = "new york"
print(city.capitalize())
print(city.title())
Output
New york
New York

Questions people ask

How do I capitalise each word?

Use str.title() or string.capwords(text).

How do I capitalise the first letter without changing the rest?

Use text[:1].upper() + text[1:].

Does capitalize() work with other alphabets?

Yes: "όλα".capitalize() gives "Όλα".

Spotted a mistake on this page? Tell us