File I/O is how Python reads from and writes to files on your computer. It’s super useful for saving data, logs, configs, and more.
This example writes some text to a file named example.txt
.
This example reads and prints the contents of example.txt
.
This example adds another line to the file without deleting what’s already there.
"w"
to write (overwrite), "r"
to read, and "a"
to append to files.