4
Reply

How can files be deleted in Python?

Dinesh Beniwal

Dinesh Beniwal

5y
2.1k
2
Reply

    To delete a file we do:

    os.remove([file_name])

    file_name is a string hence should come in inverted commas

    Using os.remove () method you can remove file

    import os
    os.remove(“demofile.txt”)

    To delete a file first need to import: import os
    then remove function of os will remove the file
    example:
    import os
    os.remove(“filename.txt”)