Overview

- The removeprefix() method of bytearray class in Python removes a given prefix from a bytearray object. The method returns the result as new bytearray.
- The prefix parameter can be any bytes-like object including a bytes literal.
Example
# Example Python program that removes the specified
# prefix in a bytearray
# Create a bytearray
buffer = bytearray(b"Well, now that we have seen each other")
prefix = b"Well, "
# Remove the prefix
prefixRemoved = buffer.removeprefix(prefix)
print("The prefix:")
print(prefix)
print("Byte array after removing the prefix:")
print(prefixRemoved)Output
The prefix:
b'Well, '
Byte array after removing the prefix:
bytearray(b'now that we have seen each other')