Assuming m
is a string, you can use endswith
:
if m.endswith('.mp3'):
...
elif m.endswith('.flac'):
...
To be case-insensitive, and to eliminate a potentially large else-if chain:
m.lower().endswith(('.png', '.jpg', '.jpeg'))
More Related Contents:
- Extracting extension from filename in Python
- Changing file extension in Python
- TypeError when run [closed]
- Reading binary file and looping over each byte
- How to get an absolute file path in Python
- Getting “Permission Denied” when running pip as root on my Mac
- Is there any other way to load a resource like an image, sound, or font into Pygame? [closed]
- How to get the index of a maximum element in a NumPy array along one axis
- Reloading module giving NameError: name ‘reload’ is not defined
- What is the pythonic way to unpack tuples? [duplicate]
- How to count the NaN values in a column in pandas DataFrame
- Plot a histogram such that bar heights sum to 1 (probability)
- Get last result in interactive Python shell
- Create file but if name exists add number
- How to one hot encode variant length features?
- Overloading Addition, Subtraction, and Multiplication Operators
- Chromedriver, Selenium – Automate downloads
- What should I do if socket.setdefaulttimeout() is not working?
- Gunicorn, no module named ‘myproject
- TkInter Label Change Font Size by Text Length
- Flatten an irregular (arbitrarily nested) list of lists
- How do I make function decorators and chain them together?
- Chrome browser initiated through ChromeDriver gets detected
- How can I use f-string with a variable, not with a string literal?
- How to add custom css file to Sphinx?
- Ellipsis lists […] and concatenating a list to itself [duplicate]
- creating a spiral array in python?
- Plot a 3D surface from {x,y,z}-scatter data
- pandas convert from datetime to integer timestamp
- ModuleNotFoundError: No module named ‘MySQLdb’