In Python 3, the readlines() method returns an iterable object, specifically a file object iterator, rather than directly returning a list as it did in Python 2. This change was made to improve efficiency and memory usage when working with large files.
When you call readlines() in Python 3, it returns an iterator that can be used to iterate over the lines of the file one by one. This iterator behaves similarly to a list, allowing you to access each line sequentially. However, unlike a list, the iterator doesn't load the entire file into memory all at once, which can be beneficial for memory-intensive operations.
You can still perform operations on the iterator object returned by readlines(), such as looping over the lines or using it in list comprehensions. If you need a list of all the lines, you can convert the iterator to a list explicitly by using the list() function, like list(file.readlines()).
Overall, in Python 3, readlines() provides the flexibility of an iterator, making it memory-efficient for working with large files, while still allowing you to access the lines in a manner similar to a list if needed.