transformation
str.title
Returns a titlecased copy where the first letter of each word is uppercase and the rest are lowercase. Word boundaries are defined by any run of non-letter characters, including apostrophes.
str.title() Parameters
| Parameter | Purpose |
|---|---|
| self | operates on the calling string; takes no arguments |
| returns | new titlecased str (original unchanged — str is immutable) |
Examples
>>> 'hello world'.title()
'Hello World' each word gets capitalized
>>> "they're here".title()
"They'Re Here" apostrophe splits the word (a common gotcha)
>>> 'HELLO WORLD'.title()
'Hello World' existing uppercase is normalized
>>> '2nd place'.title()
'2Nd Place' digits count as non-letters so the next letter capitalizes
Gotcha
The apostrophe rule ('they're' -> 'They'Re') often surprises. For proper English titles use string.capwords() or a library like `titlecase`.
Related methods
str.upper
Returns a copy of the string with all cased characters converted to uppercase. Non-cased characters (digits, punctuation, whitespace) are unchanged.
str.lower
Returns a copy of the string with all cased characters converted to lowercase. Uses Unicode simple lowercase mappings.
str.casefold
Returns a casefolded copy suitable for caseless matching. Stronger than lower(): it applies full Unicode case folding, e.g. German 'ß' becomes 'ss'.
str.replace
Returns a new string with all occurrences of substring old replaced by new. If count is given, only the first count occurrences are replaced.