You can use the os.path.splitext() function from the os.path module in Python to extract the file extension from a filename.
Here's an example:
This will output: .txt
Alternatively, you can use string slicing to extract the file extension.
This will also output: .txt
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.