File Operations – Read
.read() reads the entire file content as a string; .readlines() reads lines into a list
What it does: readlines() returns a list where each element is one line of the file. Iterating over the file object reads one line at a time. .strip() removes the \n. read() loads everything at once — fine for small files, memory-hungry for large ones. readline() advances the cursor one line — call it again to get the next. Processing line by line keeps only one line in memory at a time. The file cursor stays where reading stopped — seek(0) resets it to the start. split('\n') breaks the big string wherever there's a newline character. readlines() preserves the \n — use line.strip() or line.rstrip() to remove it.
Common mistakes: Missing parentheses read is a method, call it with (). Missing parentheses readlines is a method.
Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
.read()Fill in the Blanks
Spot the Error
Create a free class, add this module to a journey, and track who's stuck.
Create a free teacher account →No credit card. No setup fee. Make a class and invite students in under three minutes.
Practice this topic interactively, track progress, and unlock badges.
Start Learning Free →