Bytes Methods

bytes.capitalize()

Uppercase the initial byte if it is an ASCII lowercase letter, and lowercase subsequent ASCII letters. Leading punctuation, whitespace and high bytes are not skipped. Other byte values are preserved. Useful for simple ASCII labels, not language-aware capitalization. The original bytes remain unchanged; do not depend on the result having a different identity. These operations are intended for ASCII-compatible data, not arbitrary binary formats.

Formal Syntax & Structure

python syntaxpython
data.capitalize()

Return Value

bytes

bytes containing the transformed byte values; receiver unchanged.

Working Example

Example Snippetpython
data = bytes(b'hELLO API')result = data.capitalize()print(result)print(bytes(b' aBC').capitalize())print(data)
Python Reference