Bytes Methods

bytes.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

NameTypeDescription
suffixbytes-like | tuple[bytes-like, ...]Candidate binary sequence or tuple of alternatives.
startint | NoneInclusive search start; negative values count from the end.
endint | NoneExclusive 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(bytes(b'PK:DATA.bin').endswith(b'.bin'))print(bytes(b'PK:DATA.bin').endswith((b'.txt', b'.bin')))print(bytes(b'PK:DATA.bin').endswith(b'DATA', 3, 7))
Python Reference