Bytes Methods
bytes.rfind()
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. Returns -1 when absent; use membership testing if no offset is needed. 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.rfind(sub[, start[, end]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sub | bytes-like | int | Binary subsequence or single byte value from 0 through 255. |
| start | int | None | Inclusive search start; negative values count from the end. |
| end | int | None | Exclusive search end; defaults to the end of the data. |
Return Value
int
Absolute byte offset; -1 if absent.
Working Example
Example Snippetpython
print(bytes(b'AB:AB:Z').rfind(b'AB'))print(bytes(b'AB:AB:Z').rfind(58))print(bytes(b'AB:AB:Z').rfind(memoryview(b'AB'), 1, 6))