Read line number 4 from the following file
Write a python program which will read line number 4 from the following file
Write a python program which will read line number 4 from the following file
line1 line2 line3 line4 line5 line6 line7
# read file
with open("test.txt", "r") as fp:
# read all lines from a file
lines = fp.readlines()
# get line number 3
print(lines[2])
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.