Skip to main content

Program to read line number 4 from the following file

· One min read
Kaustubh Kulkarni
file.py
*# Write a program to read line number 4 from the following file*
*# Line1*
*# Line2*
*# Line3*
*# Line4*
*# Line5*
*# Line6*


def findInFile(file_name,line_no):
count=0
file=open(file_name)
lines=file.readlines()
print(lines[line_no+1])
findInFile("file.txt",4)

output:

Output
 Etiam non quam lacus suspendisse faucibus interdum posuere.

_ _