Bytes Methods

bytes.removesuffix()

Remove one exact matching suffix from the corresponding edge of the data. If the candidate is absent or empty, preserve all byte values. Unlike rstrip(), this treats the argument as an ordered sequence, not a collection of removable byte values. Introduced in Python 3.9. Returns bytes; no distinct identity guarantee.

Formal Syntax & Structure

python syntaxpython
data.removesuffix(suffix, /)

Parameters & Attributes

NameTypeDescription
suffixbytes-likeExact binary sequence to remove once if present.

Return Value

bytes

bytes with one matching edge removed, or unchanged byte values.

Working Example

Example Snippetpython
print(bytes(b'pre-pre-data-end-end').removesuffix(b'-end'))print(bytes(b'payload').removesuffix(b'none'))print(bytes(b'abc').removesuffix(b''))
Python Reference