🗒 Cheat Sheet← Lesson
BitWithBite
Python Worksheet

🐍 File Handling

Chapter: Python · Level ★☆☆ · Time: 30 min
SCORE___ / 20
NameClassDate
After this worksheet you can
Open and read filesWrite and appendUse with blocksUnderstand file modes
📚 Quick Recap

🎯 What you'll learn: Reading and writing text files with open() and the with statement. All file modes (r, w, a, r+). Reading methods: read(), readline(), readlines(). CSV files with the csv module. JSON files with json. Working with file paths using pathlib.

🧠 Section A · Concept Check ● BEGINNER 4 × 1 = 4

1Mode 'r' means:
2Best practice for opening files:
3Mode 'a' will:
4f.read() returns:

🧮 Section B · Problem Solving ● INTERMEDIATE 2 + 3×3 = 11

5Write mode is ''.
6with open(...) auto- the file.
7Open notes.txt for reading using with.
8Write 'Hi' to out.txt.
9Difference between 'w' and 'a'?

🚀 Section C · Challenge ● CHALLENGE 5

10Why use with instead of open/close?
💭 Reflection — the most useful thing I learned:
A ___/4   B ___/11   C ___/5   Total ___/20 Teacher's Signature Parent's Signature
✂ answer key — fold or cut before handing out

1-B   2-B   3-B   4-B  |  5 w   6 closes   7 = with open('notes.txt') as f:   8 = with open('out.txt','w') as f: f.write('Hi')   9 = 'w' overwrites; 'a' appends to the end  |  10 = It closes the file automatically, even on errors

📄 Need offline practice?Download the print-ready PDF or open the one-page cheat sheet.
⬇ Worksheet PDF 🗒 Cheat Sheet