all Python 3Byte sequencesfunction
bytes.endswith
bytes — search
Check whether the bytes end with a suffix.
Syntax
b.endswith(...)
The suffix must be bytes or a tuple of bytes: a str or a raw byte code is rejected with TypeError, unlike count/find, which do accept an integer. The start and end arguments carve out a slice first, and the suffix is matched against the end of that slice rather than of the whole object.
Examples
print(b'hello'.endswith(b'lo')) # → True
print(b'report.txt'.endswith((b'.txt', b'.md'))) # → True
print(b'hello'.endswith(b'hell', 0, 4)) # → True
print(b'hello'.endswith(b'')) # → True
print(b'hello'.endswith('lo')) # → TypeError
print(b'hello'.startswith(b'he')) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy