Q:

Read line number 4 from the following file using python programming

belongs to collection: Python Input and Output Exercises

0

Read line number 4 from the following file

Create a test.txt file and add the below content to it.

test.txt file:

line1
line2
line3
line4
line5
line6
line7

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

# 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])

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Print First 10 natural numbers using while loop us... >>
<< Write a python program to check if the given file ...