+ 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

9th Oct 2020, 8:21 PM
Siva sankar Reddy
Siva sankar Reddy - avatar
5 Respostas
+ 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
9th Oct 2020, 9:35 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
+ 2
Interesting question. I don't understand the meaning of "with unknown position" can you add an example of that.
9th Oct 2020, 10:15 PM
Kevin ★
+ 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.
9th Oct 2020, 10:50 PM
Kevin ★
+ 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
9th Oct 2020, 10:19 PM
Siva sankar Reddy
Siva sankar Reddy - avatar
+ 1
Through out the program we need to remember where our next() is at
9th Oct 2020, 10:21 PM
Siva sankar Reddy
Siva sankar Reddy - avatar