
Brendan V. answered 05/08/19
Math, science, and programming tutor
Yes, there are at least two ways of doing this. The first way uses the os.path module and the second uses the pathlib module.
os.path.splitext returns a tuple containing the name and extension with the preceding '.' character. The code above will print out the string ".ext".
Using pathlib
The pathlib module contains the Path class which has many methods for interacting with file paths. The .suffix property returns the file extension with preceding period.