Though not widely known, str.endswith also accepts a tuple. You don’t need to loop.
>>> 'test.mp3'.endswith(('.mp3', '.avi'))
True
More Related Contents:
- Why is it string.join(list) instead of list.join(string)?
- Remove empty strings from a list of strings
- Converting a string representation of a list into an actual list object [duplicate]
- What exactly does the .join() method do?
- Join a list of items with different types as string in Python
- How slow is Python’s string concatenation vs. str.join?
- Find and replace string values in list
- Case insensitive ‘in’
- Alphabet range in Python
- How do I split a string into a list of characters?
- Splitting on last delimiter in Python string?
- Python split string into multiple string [duplicate]
- Confused about __str__ on list in Python [duplicate]
- Joining pairs of elements of a list [duplicate]
- Finding a substring within a list in Python [duplicate]
- Perform a string operation for every element in a Python list
- Convert string to list. Python [string.split() acting weird]
- Change a string of integers separated by spaces to a list of int
- How to create a list with the characters of a string? [duplicate]
- Python: How to check a string for substrings from a list? [duplicate]
- Convert a columns of string to list in pandas
- How to apply __str__ function when printing a list of objects in Python [duplicate]
- How to return all list elements of a given length?
- Adding a string to a list using augmented assignment
- Extracting words from a string, removing punctuation and returning a list with separated words
- Deleting consonants from a string in Python
- How does str.startswith really work?
- Concatenate elements of a tuple in a list in python [duplicate]
- Join a list of strings in python and wrap each string in quotation marks
- Length of longest word in a list