How to Get File Extension from Filename in Python?
Sep 20, 2022
Hi Dev,
In this tutorial, I will show you How to Get File Extension from Filename in Python. you will learn How to Get File Extension From Path Python. you can see How to Get File Extension From Name Python. I explained simply about How to Get File Extension in Python. you will do the following things for Python Get Filename Extension from Path.
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.
so let's see following examples with output:
Example
main.py
import os
fileName, fileExtension = os.path.splitext('/images/demo.png')
print("File Name: ", fileName)
print("File Extension: ", fileExtension)
Output:
File Name: /images/demo
File Extension: .png
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?