Control Structures and Iteration
What this topic covers
Build Python conditionals and for or while loops to direct program flow. Iterate over file objects to process input incrementally instead of loading entire files into memory.
Why does iterating over a file object use less memory than calling read?
Iterating over the file object reads it one line at a time, so memory does not grow with the whole file. A read() call loads everything into one string first. Example: for line in f: process(line).