Services Work Learn About Contact
0/10
Lesson 9 of 10

File Handling

Python can read and write files easily. Use open() with modes: r (read), w (write), a (append). The with statement automatically closes the file when done.

PYTHON
# Write to a file
with open("data.txt", "w") as file:
    file.write("Hello, File!\n")
    file.write("Second line")

# Read from a file
with open("data.txt", "r") as file:
    content = file.read()
    print(content)
🧠

Quick Quiz

Answer correctly to unlock the next lesson.

Support the mission

This learning platform is 100% free: no ads, no tracking, no paywalls. If it helped you learn something useful, you can support future lessons or donate to Doctors Without Borders, which provides emergency medical care in crisis zones worldwide.

🎉

You completed Python!

You finished all 10 lessons and quizzes. You now know the basics of Python.