Python Language Iterables and Iterators Extract values one by one

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Start with iter() built-in to get iterator over iterable and use next() to get elements one by one until StopIteration is raised signifying the end:

s = {1, 2}   # or list or generator or even iterator
i = iter(s)  # get iterator
a = next(i)  # a = 1
b = next(i)  # b = 2
c = next(i)  # raises StopIteration


Got any Python Language Question?