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 298 views
1 answer 194 views
3 answers 302 views
1 answer 182 views
2 answers 232 views
1 answer 236 views
...