Bytearray Methods

bytearray.strip()

Remove consecutive eligible byte values from both ends. With no argument or None, remove ASCII whitespace (space, tab, LF, CR, vertical tab and form feed). An explicit buffer supplies individual byte values, not a literal substring. Internal bytes and high-byte values outside the selected set stay unchanged. An empty argument removes nothing. Returns a new bytearray.

Formal Syntax & Structure

python syntaxpython
data.strip(chars=None, /)

Parameters & Attributes

NameTypeDescription
charsbytes-like | NoneSet of removable byte values; None selects ASCII whitespace.

Return Value

bytearray

bytearray with selected edge byte values removed.

Working Example

Example Snippetpython
print(bytearray(b' \tABC\r\n').strip())print(bytearray(b'xyxDATAyxx').strip(b'xy'))print(bytearray(b'\xa0 A \xa0').strip())
Python Reference