readlines(limit)
limit : optional upper limit of bytes returned. fob=open('data.txt','r')
print(fob.readlines())
fob.close()
Output is here ( used the data.txt file given at file read() )
['This is first line\n', 'This is second line\n', 'This is third line\n', 'This is fourth line']
Using limit
fob=open('data.txt','r')
print(fob.readlines(10)) # ['This is first line\n']
fob.close()
We can use output as an iterator.
fob=open('data.txt','r')
my_data=(fob.readlines())
print(type(my_data)) #
for x in my_data:
print(x)
fob.close()
Output is here
This is first line
This is second line
This is third line
This is fourth line
fob = open('data.txt', 'r')
lines = fob.readlines(15) # Reads up to 15 bytes
print(lines)
fob.close()
fob = open('data.txt', 'r')
lines = fob.readlines()
non_blank_lines = [line for line in lines if line.strip()]
print(non_blank_lines)
fob.close()
writable()
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.