1#using pathlib
2from pathlib import Path
3
4file_name = Path("file.txt")
5if file_name.exists():
6 print("exists")
7else:
8 print("does not exist")
1Assuming m is a string, you can use endswith:
2
3if m.endswith('.mp3'):
4...
5elif m.endswith('.flac'):
6...
7To be case-insensitive, and to eliminate a potentially large else-if chain:
8
9m.lower().endswith(('.png', '.jpg', '.jpeg'))