demo_ref_next2.py:
mylist = iter(["apple", "banana", "cherry"]) x = next(mylist, "orange") print(x) x = next(mylist, "orange") print(x) x = next(mylist, "orange") print(x) x = next(mylist, "orange") print(x)
C:\Users\My Name>python demo_next2.py
apple
banana
cherry
orange