To delete a File, we need to import the 'os' module.
'os' module can be said to be a short form of Operating System. It has methods that supports operations that is used to interact with Operating System.
We can use the 'remove( )' method of 'os' module to delete a file.
import os os.remove("myfirstfile.txt")
And, the file 'myfirstfile.txt' is deleted from the current directory.
The 'os' module also provides a method named 'rmdir' that is used to delete a folder and its contents.
import os os.remove("myfolder")
Let us say we had a folder named 'myfolder' in the current directory. And the 'remove( )' method of 'os' module is used to delete that folder and its contents.