How to Read Multiple Lines of File in Python


In this example, we will learn how to read multiple lines of the file using the readline() function in Python.

Source Code

f = open('myfile.txt', 'r', encoding='utf-8')
line_1 = f.readline()
line_2 = f.readline()
print(line_1)
print(line_2)

Output:

Hello World!

Python is a programming language that lets you work more quickly and integrate your systems more effectively.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments