How to read the first and last line from text file in Python

1 Answer

0 votes
with open('info.txt', 'r') as f:
    first_line = f.readline()
    for last_line in f:
        pass

print(first_line)
print(last_line)


'''
run:

Python is an interpreted, 

programming language

'''

 



answered Jun 22, 2020 by avibootz

Related questions

2 answers 301 views
1 answer 195 views
3 answers 305 views
1 answer 186 views
2 answers 235 views
1 answer 240 views
...