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
| Name | Type | Description |
|---|---|---|
| suffix | str | tuple[str, ...] | One literal candidate or tuple of alternatives. |
| start | int | None | Optional inclusive start bound; negative values are relative to the end. |
| end | int | None | Optional 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'))