str.title()
Headline-style capitals: every word up — with a famous apostrophe quirk.
Common call
"war and peace".title()
Returns
new str — original unchanged
Replaces
word boundary = any non-letter, so "don't" → "Don'T"
Watch out
acronyms get flattened: "NASA" → "Nasa"
str.title()
→ str
Demo
Live evaluation
Try:
Inputs
stringstrthe source
Output
'war and peace'.title()
'War And Peace'
Every run of letters starts uppercase and continues lowercase. Watch the apostrophe case: the letter after it counts as a new word — Python’s documented quirk, reproduced faithfully here.
Common patterns
Display names and headings
Fine for simple ASCII headings; check the caveats for real names.
heading = topic.title()
Apostrophe-safe titlecasing
The docs-recommended workaround using a regex on word starts.
import re re.sub(r"[A-Za-z]+('[A-Za-z]+)?", lambda m: m.group(0).capitalize(), s)
Examples
1. Basic titlecasing
"war and peace".title()
Returns
'War And Peace'2. The apostrophe quirk
"don't stop".title()
Returns
"Don'T Stop"3. Acronyms flatten
"NASA launch".title()
Returns
'Nasa Launch'4. Digits start words
"3rd place".title()
Returns
'3Rd Place'Pitfalls
1. Apostrophes split words
Any non-letter is a boundary, so contractions get a capital mid-word.
Quirk
"they're here".title()
"They'Re Here"
Regex workaround
import re re.sub(r"[A-Za-z]+('[A-Za-z]+)?", lambda m: m.group(0).capitalize(), s)
"They're Here"
2. Acronyms and mixed case are destroyed
title() lowercases everything after each first letter.
Flattened
"visit NASA HQ".title()
'Visit Nasa Hq'
Capitalize selectively
" ".join(w if w.isupper() else w.capitalize() for w in s.split())
'Visit NASA HQ'
3. Small words get capitalized too
Real headline style leaves "and", "of", "the" lowercase — title() has no such rules.
Not editorial style
"lord of the rings".title()
'Lord Of The Rings'
Roll your own rules
SMALL = {"of", "the", "and"} " ".join(w if w in SMALL and i else w.capitalize() for i, w in enumerate(s.split()))
'Lord of the Rings'
When to use
Use it
- Quick headline casing of simple ASCII text
- Display formatting where the quirks cannot occur
Reach for something else
- Contractions or possessives present → regex workaround
- Acronyms must survive → custom per-word logic
- Sentence case → str.capitalize
Notes
Complexity
O(n)
Return
new str — source untouched
CPython impl
Objects/unicodeobject.c :: do_title
Memory
One new string
Thread-safe
Yes — str is immutable
FAQ
title() defines a word as a run of letters. The apostrophe is not a letter, so "t" starts a new word and gets capitalized. The docs themselves show a regex workaround.
History
2.0
Method available on the unified string type.