Reading and Writing Files in Python
1 of 4ICT
Reading and Writing Files in Python
For grown-ups
Companion summary
Have you ever wondered how apps remember your settings after you close them? Every app you use — from games to music players — reads and writes files to save your data. Python can open a file in just one line of code using the built-in open function. When you finish, try writing a program that saves a user's name to a text file and reads it back.
Where Does Your Data Go?
Where Does Your Data Go?
Imagine you write a high score in a game. You close the game, turn off your computer, and come back the next day — and your score is still there. How? A program must have saved it somewhere. Variables store data while a program runs, but they vanish the moment the program stops. To keep data permanently, programs write it to a file on the storage drive. In this lesson you will learn exactly how Python does that.
💭 Think about this
Think of two real-world programs (apps, games, or tools) that must save data between uses. What kind of data do you think they store in files?