Free cookie consent management tool by TermsFeed The removesuffix() method of bytearray class in Python | Pythontic.com

The removesuffix() method of bytearray class in Python

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:

# 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:

Text after removing the suffix:
bytearray(b'The sands were dry')

 


Copyright 2025 © pythontic.com