How to Capitalize Each Word of a String in Python with title()
A name typed as ada lovelace looks careless on a greeting or a label. title() gives you a copy of the text in which every word starts with a capital letter: Ada Lovelace. This guide does it on Python 3.15.2.
Syntax
<new_text> = <text>.title()
| Part | What it means |
|---|---|
<text> | The string to convert |
.title() | Returns a new string in which each word starts with a capital letter and the rest of each word is lowercase |
<new_text> | The new string. <text> itself doesn't change |
The Python documentation says str.title() will "Return a titlecased version of the string where words start with an uppercase character and the remaining characters are lowercase."
The Example
A variable holds the name ada lovelace, all in small letters. The script prints it with title(), then prints the original to show that it didn't change.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
name = "ada lovelace"
print(name.title())
print(name)

Step 2: Run It
uv run python names.py
Ada Lovelace
ada lovelace

name.title() gave Ada Lovelace: both words now start with a capital letter. name itself still says ada lovelace, because Python strings can't be changed: the documentation calls them "immutable sequences of Unicode code points", so title() builds a new string instead. The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Expecting name.title() to change name | name still prints ada lovelace, as Step 2 showed | Save the result: after name = name.title(), print(name) printed Ada Lovelace |
Using title() on text with apostrophes | "they're bill's friends".title() gave They'Re Bill'S Friends | Use string.capwords(), as the FAQ below shows |
FAQ
Why does title() capitalize the letter after an apostrophe?
Because of how it finds words. The documentation explains: "The algorithm uses a simple language-independent definition of a word as groups of consecutive letters." An apostrophe isn't a letter, so in they're, the re after it counts as a word of its own, and "they're bill's friends".title() gave They'Re Bill'S Friends. The documentation adds that the string.capwords() function "does not have this problem, as it splits words on spaces only". This script:
import string
print(string.capwords("they're bill's friends"))
printed They're Bill's Friends.
What happens to capital letters in the middle of a word?
They become lowercase. "aDA LOVELACE".title() gave Ada Lovelace: only the first letter of each word stays a capital.
How is capitalize() different?
capitalize() gives a capital letter only to the first character of the whole string, and makes the rest lowercase. "ada lovelace".capitalize() gave Ada lovelace, with a small l. The documentation describes it as "Return a copy of the string with its first character capitalized and the rest lowercased." Use title() when every word should start with a capital letter, and capitalize() for a sentence.
Conclusion
name.title() returned Ada Lovelace, a new string in which each word starts with a capital letter, while name stayed ada lovelace.
Additional Resources
- str.title() — the method, with its apostrophe example.
- str.capitalize() — capitalizes only the first character.
- string.capwords() — splits the text at whitespace and capitalizes each word.
