Sometimes, we want to delete a file or folder in Python.
In this article, we’ll look at how to delete a file or folder in Python.
How to delete a file or folder in Python?
To delete a file or folder in Python, we can use the os.remove
method.
For instance, we write:
import os
os.remove("data.txt")
We call os.remove
with the path of the file or folder to remove.
Conclusion
To delete a file or folder in Python, we can use the os.remove
method.