1import pathlib
2
3print(pathlib.Path('yourPath.example').suffix) # '.example'
4#or
5import os
6filename, file_extension = os.path.splitext('/path/to/somefile.ext')
1>>> import os
2>>> filename, file_extension = os.path.splitext('/path/to/somefile.ext')
3>>> filename
4'/path/to/somefile'
5>>> file_extension
6'.ext'