bytes.title()
Headline case, where a "word" starts after ANY non-letter. That rule is what turns it's into It'S and makes title unsuitable for real names.
Demo
A letter is uppercased whenever the byte before it is not a letter — so the start of the data, a space, a hyphen and a digit all begin a new word. That is why well-known becomes Well-Known and abc1def becomes Abc1Def. Everything else is lowercased, which is why uppercase input comes out as Hello World rather than staying shouted. The apostrophe case is the famous one: it's becomes It'S, because the apostrophe is not a letter.
Common patterns
heading = raw.title()
if data.istitle(): ...
import string string.capwords(data.decode('utf-8'))
Examples
Pitfalls
b"it's".title()
import string string.capwords("it's")
b'NASA launch'.title()
b' '.join(w if w.isupper() else w.title() for w in data.split())
'élan vital'.encode().title()
'élan vital'.title().encode()
When to use
- Headline-casing simple ASCII labels with plain spaces
- Quick normalisation of consistently formatted input
- Anything with apostrophes, hyphens or digits inside words
- Names and acronyms that must keep their own casing
- Real text → decode and use string.capwords
Notes
FAQ
Because title starts a new word after any byte that is not a letter, and an apostrophe is not a letter. The s is therefore the first letter of a "word" and gets uppercased. There is no option to change this rule; use string.capwords on decoded text instead.
import string string.capwords("it's here") # "It's Here"