print file extension python code example
Example 1: 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
Example 2: os extension
>>> os.path.splitext('/a/b.c/d')
('/a/b.c/d', '')