Back
There are many ways to do it, I'll discuss a few with you:
Use pathlib
import pathlib
print(pathlib.Path('xyz path').suffix)
Or
Use import function
import os.path
extension = os.path.splitext(xyz file)[2][2:]
Happy Learning......!!
Learn more about Python from an expert. Enroll in our Python Course.
You can use below-mentioned code for extracting extension from filename in Python:-
import os.pathextension = os.path.splitext(filename)
extension = os.path.splitext(filename)
You can use the following video tutorials to clear all your doubts:-
31k questions
32.8k answers
501 comments
693 users