import os.path extension = os.path.splitext(filename)[1]
import pathlib print(pathlib.Path('yourPath.example').suffix) # '.example' #or import os filename, file_extension = os.path.splitext('/path/to/somefile.ext')