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 296 views
1 answer 192 views
3 answers 296 views
1 answer 180 views
2 answers 229 views
1 answer 235 views
...