Python Glossary Русский

Python 3.3+Byte sequencesfunction

bytearray.clear

bytearray — mutating

Remove all bytes (make it empty).

Syntax

ba.clear(...)

It mutates the object itself, so every name bound to that buffer sees it become empty; if other references must keep the old content, rebind with ba = bytearray() instead of clearing. It is exactly equivalent to del ba[:], and immutable bytes has no such method at all.

Examples

ba = bytearray(b'abc')
ba.clear()
print(ba)   # → bytearray(b'')

See also

Open in the full glossarydocs.python.orgReport an inaccuracy