str.capitalize()

Sentence case: first character up, everything else down — including characters that were already uppercase.

String methodPython 2.0+Live demo
Common call
"hello world".capitalize()
Returns
new str — original unchanged
Replaces
the REST is lowercased too — acronyms get flattened
Watch out
per-word capitals is str.title, not capitalize
str.capitalize()
str

Demo

Live evaluation
Try:
Inputs
stringstrthe source
Output
'hello world'.capitalize()
'Hello world'

Only the first character is raised — and note what happens to the rest: it is actively lowercased, which flattens acronyms and mid-string capitals. A leading digit stays as is, and the rest still lowercases.

Common patterns

Sentence-case user input
Normalize free-text answers for display.
display = answer.strip().capitalize()
Per-word capitals
That is title(), or capitalize per word via split/join for more control.
" ".join(w.capitalize() for w in name.split())

Examples

1. Basic sentence case
"hello world".capitalize()
Returns
'Hello world'
2. All caps get flattened
"HELLO".capitalize()
Returns
'Hello'
3. Leading digit
"3rd place".capitalize()
Returns
'3rd place'
4. Empty string
"".capitalize()
Returns
''

Pitfalls

1. It lowercases the rest
capitalize is not "raise the first letter" — it is full sentence-casing.
Acronym lost
"NASA launched".capitalize()
'Nasa launched'
First letter only
s[:1].upper() + s[1:]
'NASA launched'
2. Not per-word
For headline-style capitals use title() — with its own apostrophe caveats.
One word only
"hello world".capitalize()
'Hello world'
Per word
"hello world".title()
'Hello World'

When to use

Use it
  • Sentence-casing display text
  • Normalizing shouty ALL-CAPS input
Reach for something else
  • Preserve the rest of the string → s[:1].upper() + s[1:]
  • Per-word capitals → str.title
  • Locale-aware casing → not built in; consider PyICU

Notes

Complexity
O(n)
Return
new str — source untouched
CPython impl
Objects/unicodeobject.c :: do_capitalize
Memory
One new string
Thread-safe
Yes — str is immutable

FAQ

Slice it manually — there is no built-in for that.

s[:1].upper() + s[1:]

History

3.8
First character now titlecased (affects some ligatures/digraphs) rather than uppercased.
2.0
Method available on the unified string type.