Welcome back for another way of the programmer segment.
Students sometimes get confused with
iteration about what's the iterator variable and what's the iterable So,
I want to just go through and give you a little practice.
To have a series of questions that ask,
what's the type of your iterable or what's the type of your iterator?
Here, I have a variable N,
and I am iterating through it.
The iterable is the thing that we are going to iterate through,
it goes after the word N. In this case, it is a list.
Hurray! We got that one right.
Some of them may get a little trickier.
Here, what's the type of our iterable?
Again, the iterable is after the word N,
it's the variable T. I have deliberately for
these exercises given a variable names that don't give things away.
This is not good coding style,
better to have meaningful names,
but this is forcing you to reason about it.
T is going to be a string.
What will the type of my iterable be here?
Again, is the thing after the N,
is the variable Y, whose value is 18.
You might be tempted to say that it's an integer,
but of course an integer is not a sequence at all.
You can't iterate through it.
So, this one's going to be an error that we can't iterate over the object.
What's the type of my iterable here?
Will the open parentheses rather than
the brackets are an indicator that this is a tuple rather than a list.
I'm going to go on to some that ask us about what the iterator variable.
So now, what is the type of your iterator variable?
Here it's not asking you about the iterable,
not the sequence, but the iterator variable.
So Z, what kind of thing will Z be
bound to when we get down to print Z on the third line?
Will Z will be bound to one of the things that is in the iterable,
one of the things that's in T. So,
in this case, Z will be a string.
What will be the type of my iterator variable on the first iteration?
So, Z will be bound to nine on the first iteration.
So, Z will be an integer.
So, I think you get the idea here.
I'm really just trying to reinforce the vocabulary.
The iterable is the sequence.
It's the thing that you iterate through,
its a thing that goes after the word N.
The iterator variable is
the variable name between the word for and the word in,
and it will be bound each time to one item from the iterable,
one item from the sequence.
So, don't get confused.
The iterable is a thing that you iterate through, goes after the in.
The iterator variable is the thing that's bound to
each item in the sequence. We'll see you next time.