Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

str.endswith

Tests whether a string ends with a suffix or any suffix in a tuple.

Version: Python 3.14; repository image, production runtime not attested

Syntax

s.endswith(suffix[, start[, end]])

Tests whether a string ends with a suffix or any suffix in a tuple.

Matching is case-sensitive. Normalize both sides first when the application treats case variants alike.

Optional start and end bounds restrict the tested region, excluding the end position. The first filename matches .csv in the suffix tuple. Uppercase letters in the second filename prevent the literal lowercase match.

Examples

print("map.csv".endswith((".csv", ".tsv")))
print("map.CSV".endswith(".csv"))

Result

True
False

Optional start and end bounds restrict the tested region, excluding the end position. The first filename matches .csv in the suffix tuple. Uppercase letters in the second filename prevent the literal lowercase match.

Sources