How to check if a string ends with any string from a list in Python

A suffix is a substring that ends a string. For example, “c” and “bc” are suffixes of “abc”.

Solution for How to check if a string ends with any string from a list in Python : You can use string.endswith() to check if a string ends with any string from a list Call str.endswith(suffix) to check if str ends with suffix. suffix can be a string or a tuple of strings. Convert the list to a tuple and set it as suffix to check if any of the elements are suffixes.


how-to-check-if-a-string-ends-with-any-string-from-a-list-in-python