How to check if a file exists using Python

1 min

Here is how to check if a file exists in a folder in Python.

import os

if os.path.isfile("file.txt"):
    print("File exists")
else:
    print("File does not exist")

If you want to learn how to write a file in Python

How to write a text file in Python
Learn how to write a text file in Python in only 4 lines of code.

Or how to store files efficiently in Python

How to store data efficiently in Python
How to store data in Python. All the different file formats you can use with Python.