Python Glossary Русский

all Python 3Byte sequencesfunction

bytearray.title

bytearray — case

Return a title-cased copy.

Syntax

ba.title(...)

A word here is just a run of ASCII letters, and every other byte is a boundary — digits, hyphens and apostrophes all start a new "word", which mangles contractions and hyphenated forms. For human-readable headings this is rarely what you want, especially since non-ASCII bytes are left alone entirely; decode() first and capitalise word by word yourself.

Examples

print(bytearray(b'hi there').title())   # → bytearray(b'Hi There')
print(bytearray(b'HELLO WORLD').title())   # → bytearray(b'Hello World')
print(bytearray(b'a1b2 c3').title())   # → bytearray(b'A1B2 C3')
print(bytearray(b"they're here").title())   # → bytearray(b"They\'Re Here")
ba = bytearray(b'abc')
print(ba.title(), ba)   # → bytearray(b'Abc') bytearray(b'abc')

See also

Open in the full glossarydocs.python.orgReport an inaccuracy