The removesuffix() method of bytearray class in Python

The removesuffix() method of bytearray class in Python removes a specified suffix and returns a new bytearray object. The suffix parameter is a bytes-like object.

Bytearray Updated 15 Nov 2025 1 min read

Overview

  • The removesuffix() method of bytearray removes a given suffix from a bytearray object. The resultant sequence is returned as a new bytearray object.
  • The suffix is any bytes-like object. For example, the suffix can be a bytes or a bytearray object.

The removesuffix() of bytearray class in Python

Example

python
# Example Python program that removes

# a suffix from a bytearray.

# Bytearray creation

text  = bytearray(b"The sands were dry as dry")

# Remove the suffix from the bytearray

suffix =  b" as dry"

suffixRemoved = text.removesuffix(suffix)

print("Text after removing the suffix:")

print(suffixRemoved)

Output

Output
Text after removing the suffix:

            bytearray(b'The sands were dry')