Can we use readlines function to count no. of new line character in files in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we use readlines function to count no. of new line character in files in python?

Question is regarding file in python.

30th Jan 2020, 11:44 AM
Amey Godse
Amey Godse - avatar
1 Answer
+ 5
with open('file.txt') as f: print(len(f.readlines()))
30th Jan 2020, 11:55 AM
Aymane Boukrouh
Aymane Boukrouh - avatar