all Python 3Strings (str)function
str.endswith
search
True if the string ends with the suffix (or one of a tuple of suffixes).
Syntax
s.endswith(suffix[, start[, end]])
The argument must be a string or a tuple of strings — a list raises TypeError, which bites people who build their extension list dynamically (wrap it in tuple()). Matching is case-sensitive, so an uppercase extension will not match '.py'; lowercase the name first, or compare Path(...).suffix instead.
Examples
print('file.py'.endswith('.py')) # → True
print('file.py'.endswith('.txt')) # → False
print('file.py'.endswith(('.py', '.txt'))) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy