Python Glossary Русский

all Python 3Byte sequencesfunction

bytes.title

bytes — case

Return a title-cased copy (each word capitalized).

Syntax

b.title(...)

A word here is just a maximal run of ASCII letters, and any other byte counts as a separator, so an apostrophe or a digit ends the word and the next letter gets capitalized again. That makes it unfit for real headings — contractions and abbreviations come out mangled, so use a regex or your own word-by-word pass instead.

Examples

print(b'hello world'.title())   # → b'Hello World'
print(b'HELLO WORLD'.title())   # → b'Hello World'
print(b"they're ok".title())   # → b"They'Re Ok"
print(b'x2y'.title())   # → b'X2Y'
print(b'hello world'.capitalize())   # → b'Hello world'

See also

Open in the full glossarydocs.python.orgReport an inaccuracy