Real applications store data. File handling is how Python talks to files on your system.
file = open("data.txt", "r")
content = file.read()
file.close()
r — Readw — Write (overwrite)a — Appendx — Create
file = open("log.txt", "w")
file.write("Hello Python\n")
file.close()
file = open("log.txt", "a")
file.write("New entry\n")
file.close()
with open("data.txt", "r") as file:
print(file.read())
with open("data.txt") as file:
for line in file:
print(line.strip())
File handling is the bridge between programs and persistence.
Next: Virtual Environments & pip