9/10/26Less than 1 minuteAbout 140 words
Concept: Reading files
There are two common ways to read the contents of a file in Python: using the readlines() method or iterating over the file handle directly. Each has their own advantages and disadvantages, and the choice of which to use depends on the specific use case.
| Reading method | Example | When to use |
|---|---|---|
readlines() | ![]() | Use for small files that can fit into memory. Where you need list methods to process the data. |
| Iterating over the file handle | ![]() | Use for large files that cannot fit into memory. Where you need to process the data line by line. |

