write number of lines in file python

f = open("filename", "r") #Load file in any mode that's able to read, ie r, r+, w+ etc

#to get length

#To iterate over each line
for line in f.readlines(): #file.readlines(), splits the file into a list, where each element is a seperate line

Here is what the above code is Doing:
1. Open the file in read mode
2. Read the file into a list
3. Iterate over each element in the list
4. Print each element