+ 1
What is purpose of next()
I'm not able to understand when there is soo many ways to iter what is the use of next() with unknown position
5 Réponses
+ 4
Python file method next() is used when a file is used as an iterator, typically in a loop, the next() method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit. ... However, usingseek() to reposition the file to an absolute position will flush the read-ahead buffer.
more info:
https://www.w3schools.com/python/ref_func_next.asp
+ 2
Interesting question.
I don't understand the meaning of "with unknown position" can you add an example of that.
+ 2
next will return the next value yielded by the iterator, no matter where the call is located.
next(g) will return the first value (1)
Then:
next(g) will return the second value (2)
next is used when you want to get the values one by one manually.
When you iterate using a for loop it just does that job for you.
+ 1
G=iter[1,2,3]
Next(g)
#bla bla bla
Bla bla bla
Bla bla
Next(g)
Can u tell what is value return by next this time
+ 1
Through out the program we need to remember where our next() is at