Bytearray Methods
bytearray.endswith()
Test whether the selected byte range ends with a literal binary sequence. A tuple allows alternative candidates; they are tried in order until one matches. A single integer is not accepted, unlike find(). Empty candidates match valid boundaries, but not a start beyond the data length. No text decoding or case conversion occurs.
Formal Syntax & Structure
python syntaxpython
data.endswith(suffix[, start[, end]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| suffix | bytes-like | tuple[bytes-like, ...] | Candidate binary sequence or tuple of alternatives. |
| 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
bool
True if a candidate matches at the specified edge; False otherwise.
Working Example
Example Snippetpython
print(bytearray(b'PK:DATA.bin').endswith(b'.bin'))print(bytearray(b'PK:DATA.bin').endswith((b'.txt', b'.bin')))print(bytearray(b'PK:DATA.bin').endswith(b'DATA', 3, 7))