python check file extension

Do you want to know the information about “python check file extension”. If yes, you’re in the correct tutorial.

python check file extension

# Checking for single extension (.txt) of file
if file.endswith(".txt"):
  # do something
# Checking multiple extensions (.txt, .pdf, .mp3, ...)
if file.endswith((".txt", ".pdf", ".mp3")):
  # do something

Final Thoughts

I hope this article helps you to know about “python check file extension”. If you have any questions regarding this tutorial please let us know via the comment section. Share this article with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment