Bytearray Methods

bytearray.rindex()

Locate the last matching byte offset. Searches accept a bytes-like object or a single integer byte (0–255). Bounds restrict complete matches; offsets are relative to the original sequence. Raises ValueError when absent. Empty patterns match boundaries, but a start greater than the original length does not match. Positions count bytes, not decoded characters. Integer search support was added in Python 3.3.

Formal Syntax & Structure

python syntaxpython
data.rindex(sub[, start[, end]])

Parameters & Attributes

NameTypeDescription
subbytes-like | intBinary subsequence or single byte value from 0 through 255.
startint | NoneInclusive search start; negative values count from the end.
endint | NoneExclusive search end; defaults to the end of the data.

Return Value

int

Absolute byte offset; raises ValueError on absence.

Working Example

Example Snippetpython
print(bytearray(b'AB:AB:Z').rindex(b'AB'))print(bytearray(b'AB:AB:Z').rindex(58))print(bytearray(b'AB:AB:Z').rindex(memoryview(b'AB'), 1, 6))
Python Reference