How Do You Use the “next” Function to Iterate Through an Iterable in Python?

Problem scenario
You want to use the reserved word "next" to parse through an iterable. What do you do?

Solution
Run this six-line program as an illustration:

contint = [ 15, 50, -100, 'foobar']
var1=iter(contint)
print(next(var1))
print(next(var1))
print(next(var1))
print(next(var1))

Leave a comment

Your email address will not be published. Required fields are marked *