Skip to main content

What is a File?

Variables and lists store data in RAM. This data is temporary and disappears when the program stops. Files store data permanently on your disk.

We use the built-in open() function to work with files.

Common File Modes:

  • 'r' (Read): Opens a file for reading (throws an error if the file does not exist).
  • 'w' (Write): Opens a file for writing (creates a new file if missing, or overwrites existing content).
  • 'a' (Append): Opens a file for adding data at the end (does not delete existing data).