Categories
Python Answers

How to delete a file or folder in Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *