How does the function .readline() know which line it schould save in the variable?
I’m currently here: Learn Python: Files Reading a Line on the first instruction.
The example is
and the explanation is as following:
" This script also creates a file object called sonnet_doc
that points to the file millay_sonnet.txt. It then reads in the first line using sonnet_doc.readline()
and saves that to the variable first_line
. It then saves the second line (So make the most of this, your little day,
) into the variable second_line
and then prints it out."
how can Python know that if you which line you want to wo save inside a variable. Why is the the second line stored in the variable “second_line” whe the exact same command ( sonnet_doc.readline() ) is given. In this function there isn’t writen any argument or something else which could show the maschine that is should place the second line from the file into the variable “second_line” instead of the first line from the text. The Variable “second_line” could also be named “grasshopper”. Would Python still know that is should assing the second line in the file to the “grasshopper” variable? If Yes, Why? How? and how can i controll that?