Chapters
Python114 chapters

ReferenceString methods

str.endswith()

Whether the string ends with the given text, or any of several.

Signature

text.endswith(suffix)

Parameters

NameMeans
suffixa string, or a tuple of strings

Returns

A bool.

Example

Python
for name in ["a.png", "b.txt"]:
    print(name, name.endswith((".png", ".jpg")))

Output

a.png True
b.txt False

See also