all Python 3Byte sequencesfunction
bytearray.remove
bytearray — mutating
Remove the first occurrence of a byte value.
Syntax
ba.remove(...)
The argument is an int in 0-255, not a bytes literal: ba.remove(b'b') fails with TypeError, so write ba.remove(98) or ba.remove(ord('b')). Only the leftmost occurrence goes away, and if the byte is absent you get a ValueError — check with in first or wrap the call in try.
Examples
ba = bytearray(b'abc')
ba.remove(98)
print(ba) # → bytearray(b'ac')
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy