The methods that can be used to perform these tasks are imported in the python program using os library in python.
Deleting a file
Deleting a file will simply delete the given file from its directory. This is done using remove() method present in os library.
Syntax:
os.remove()
The method accepts the path or path of the file to be deleted.
We can delete a file present in your system using remove() method by entering the full path of the file to the function.
Program to delete a file in python
Output:
Explanation:
In the above code, we have deleted the file data.txt using the os.remove() method.
need an explanation for this answer? contact us directly to get an explanation for this answer