Python Get File Extension from Filename Example

By Hardik Savani July 1, 2022 Category : Python

This tutorial is focused on python get file extension from filename. you can understand a concept of python get file extension from path. let’s discuss about python get filename extension from path. it's simple example of how to get file extension in python. You just need to some step to done how to get file extension from path python.

In this example, I will give you a simple example of getting the file extension from file path. so let's see a simple example with output.

You can use these examples with python3 (Python 3) version.


import os
fileName, fileExtension = os.path.splitext('/images/demo.png')
print("File Name: ", fileName)
print("File Extension: ", fileExtension)


File Name:  /images/demo
File Extension:  .png

I hope it can help you...

Tags :