Bytearray Methods
bytearray.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. Returns a new mutable buffer even when no changes are needed; the original is untouched. These operations are intended for ASCII-compatible data, not arbitrary binary formats.
Formal Syntax & Structure
python syntaxpython
data.capitalize()Return Value
bytearray
bytearray containing the transformed byte values; receiver unchanged.
Working Example
Example Snippetpython
data = bytearray(b'hELLO API')result = data.capitalize()print(result)print(bytearray(b' aBC').capitalize())print(data)print(result is data)