String Methods

str.endswith()

Test whether the bounded text ends with the specified suffix. Accept a string or a tuple of candidate strings, testing until a match is found. Matching is exact and case-sensitive, not a regular expression. Empty candidates match valid boundaries; a tuple with no candidates fails. The original string is unchanged.

Formal Syntax & Structure

python syntaxpython
text.endswith(suffix[, start[, end]])

Parameters & Attributes

NameTypeDescription
suffixstr | tuple[str, ...]One literal candidate or tuple of alternatives.
startint | NoneOptional inclusive start bound; negative values are relative to the end.
endint | NoneOptional exclusive end bound; defaults to the end.

Return Value

bool

True if any candidate matches the requested boundary; otherwise False.

Working Example

Example Snippetpython
filename = "api.json"print(filename.endswith('.json'))print(filename.endswith(('.json', "other")))print(filename.endswith('api'))
Python Reference