File Operations – Read
.read() reads the entire file content as a string; .readlines() reads lines into a list
Understanding File Operations – Read in Python
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 class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 41–50) and word search (Modules 41–63).
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
Student with a class code? Join your class →