In this example we will show how to check if a file exists and then delete it in Python.
Source Code
import os
if os.path.exists('filename.py'):
os.remove('filename.py')
else:
print('The file does not exist.')
Output:
The file does not exist.