Files and functions _ Retrieving the second or third line output
Hi
From the underlining code. After obtaining the first line output. Going further, how do you retrieve the second or third line.
f = open('kipling.txt','r')
print(f.readline())
f.close()
print()
1 answers ( 0 marked as helpful)
Hey Ashakah,
Let me make use of the content
variable that Giles defines at 7:55. If you want to obtain the variables line by line, you can iterate through that variable in, for example, the following way:
for i in content:
print(i)
If you want a specific line, then you can type
print(content[# your index #])
where you replace # your index #
with the index of the line that you want to print out.
Hope this helps!
Kind regards,
365 Hristina