The first argument is required. Let’s call it
sequence. That’s the iterable that your
my_enum(), will loop through. Also, you learned that there is an optional value called
start, and by default it should also be
0, but you could possibly even change this and say, well,
my_enum() function should start with
5 because why not?
But we stick to the zero for now and create a
count variable inside of this function that takes over this value. So the default value of
0, and inside the function, you initialize a
count variable. This should be the value of
Oops, I just spotted there is a typo. So let’s check. The argument you’re passing in,
sequence, is the one you’re using inside of it, and then you’re looping through it, and you’re yielding
item. In the end, you’re incrementing
1, so every time you’re stepping through this
for loop, you count up
The yielding statement makes this function a generator function. You will learn in the next lesson, by using your
my_enum() function, what exactly this does, but for now you have created enough to actually use it.
Become a Member to join the conversation.