The remove() method of bytearray class in Python

In Python, given the integer value in the range of 0 to 255, the remove() method removes the corresponding element from a given bytearray.

Bytearray Updated 8 Jan 2026 1 min read

Overview

  • The remove() method accepts an integer value in the range (0, 255) and removes the corresponding element from the bytearray.

Example

python
# Example Python program that removes an

            # element whose value matches a given value

            # using the remove() method

firstLine = bytearray(b"Hey diddle, diddle!")

            print("Original bytearray:")

            print(firstLine)

# Remove an element by providing the ASCII value

            firstLine.remove(ord(b"!"))

            print("The new bytearray:")

            print(firstLine)

# Remove an element whose ASCII value matches

            # the character ","

            firstLine.remove(ord(b","))

            print("Bytearray after another removal of an element:")

            print(firstLine)

Output

Output
The new bytearray:

            bytearray(b'Hey diddle, diddle')

            Bytearray after another removal of an element:

            bytearray(b'Hey diddle diddle')