Use readlines() when a file’s contents need to become a list instead of one large string. Each list item represents one line and usually includes its newline character. section 5.0
Read a drink menu
For a file containing coffee, chocolate, and decaf, f.readlines() produces ['coffee\n', 'chocolate\n', 'decaf\n']. Check type(drinks) to see that the result is a list. To remove the newline characters, loop over the items and apply strip(). section 5.0
f = open("drinks.txt")
drinks = f.readlines()
print(drinks)
Compare the readlines() call with its printed list result and type check. section 5.0
A practical file-reading pattern is:
- Call readlines() on an opened file. section 5.0
- Loop through the returned lines, strip each item, and append the cleaned value to a new list. section 5.0

