Example 1: Using os module
Output
file
basename() gives the name of the last file/folder of the path, whereas splitext() splits the file name into filename and extension.
Output
('file', '.ext')
Example 2: Using Path module
Output
file
Using stem attribute of Path module, the file name can be extracted as shown above.
It works for python 3.4 and above.