endswith also accepts a tuple
Have you ever written something like this?
fname = 'movie.avi' if fname.endswith('avi') or fname.endswith('mp4'): print("It's a movie.")
endswith also accepts a tuple. Just saying.
fname = 'movie.avi' if fname.endswith(('avi', 'mp4')): print("It's a movie.")
Meaning: if it ends as ‘
avi‘ or ‘
This also works with
startswith, of course.
Thanks to one of my students, Marton Sz. who solved one of his exercises using this trick.