In this tutorial, you will learn how to delete a file using the Python programing language. Deleting files using Python is very simple. You can delete files using the os.remove()
method. You can delete a file using both relative path and absolute path. Below is the example code.
Remove file with relative path
import os
# removing a file with relative path
os.remove("file_1.txt")
Remove file with absolute path
import os
# remove file with absolute path
os.remove(r"c:\test\file_2.txt")
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.