all Python 3Byte sequencesfunction
bytearray.strip
bytearray — stripping
Strip bytes (whitespace by default) from both ends.
Syntax
ba.strip(...)
With no argument only ASCII whitespace bytes are removed (space, \t, \n, \r, \v, \f); bytes have no notion of Unicode spaces, so a UTF-8 non-breaking space survives. And although bytearray is mutable, strip() is not in-place: it hands back a new object that you have to assign somewhere.
Examples
print(bytearray(b' hi ').strip()) # → bytearray(b'hi')
print(bytearray(b'xxhixx').strip(b'x')) # → bytearray(b'hi')
print(bytearray(b'\n data \t').strip()) # → bytearray(b'data')
print(bytearray(b'ababhiba').strip(b'ab')) # → bytearray(b'hi')
print(bytearray(b'hello').strip(b'lo')) # → bytearray(b'he')
print(bytearray(b' hi ').lstrip()) # → bytearray(b'hi ')
See also
Open in the full glossarydocs.python.orgReport an inaccuracy