1 00:00:00,470 --> 00:00:04,545 Welcome back for another way of the programmer segment. 2 00:00:04,545 --> 00:00:07,950 Students sometimes get confused with 3 00:00:07,950 --> 00:00:11,820 iteration about what's the iterator variable and what's the iterable So, 4 00:00:11,820 --> 00:00:14,625 I want to just go through and give you a little practice. 5 00:00:14,625 --> 00:00:16,890 To have a series of questions that ask, 6 00:00:16,890 --> 00:00:20,460 what's the type of your iterable or what's the type of your iterator? 7 00:00:20,460 --> 00:00:24,975 Here, I have a variable N, 8 00:00:24,975 --> 00:00:27,135 and I am iterating through it. 9 00:00:27,135 --> 00:00:30,720 The iterable is the thing that we are going to iterate through, 10 00:00:30,720 --> 00:00:37,030 it goes after the word N. In this case, it is a list. 11 00:00:45,020 --> 00:00:48,340 Hurray! We got that one right. 12 00:00:48,670 --> 00:00:52,170 Some of them may get a little trickier. 13 00:00:53,840 --> 00:00:57,195 Here, what's the type of our iterable? 14 00:00:57,195 --> 00:01:01,040 Again, the iterable is after the word N, 15 00:01:01,040 --> 00:01:04,040 it's the variable T. I have deliberately for 16 00:01:04,040 --> 00:01:08,410 these exercises given a variable names that don't give things away. 17 00:01:08,410 --> 00:01:10,095 This is not good coding style, 18 00:01:10,095 --> 00:01:11,630 better to have meaningful names, 19 00:01:11,630 --> 00:01:14,165 but this is forcing you to reason about it. 20 00:01:14,165 --> 00:01:17,370 T is going to be a string. 21 00:01:23,630 --> 00:01:27,260 What will the type of my iterable be here? 22 00:01:27,260 --> 00:01:29,930 Again, is the thing after the N, 23 00:01:29,930 --> 00:01:32,675 is the variable Y, whose value is 18. 24 00:01:32,675 --> 00:01:36,460 You might be tempted to say that it's an integer, 25 00:01:36,460 --> 00:01:39,720 but of course an integer is not a sequence at all. 26 00:01:39,720 --> 00:01:41,430 You can't iterate through it. 27 00:01:41,430 --> 00:01:47,130 So, this one's going to be an error that we can't iterate over the object. 28 00:01:49,000 --> 00:01:52,030 What's the type of my iterable here? 29 00:01:52,030 --> 00:01:56,075 Will the open parentheses rather than 30 00:01:56,075 --> 00:02:03,270 the brackets are an indicator that this is a tuple rather than a list. 31 00:02:14,690 --> 00:02:22,240 I'm going to go on to some that ask us about what the iterator variable. 32 00:02:22,400 --> 00:02:26,395 So now, what is the type of your iterator variable? 33 00:02:26,395 --> 00:02:28,405 Here it's not asking you about the iterable, 34 00:02:28,405 --> 00:02:31,775 not the sequence, but the iterator variable. 35 00:02:31,775 --> 00:02:35,790 So Z, what kind of thing will Z be 36 00:02:35,790 --> 00:02:39,780 bound to when we get down to print Z on the third line? 37 00:02:39,780 --> 00:02:44,230 Will Z will be bound to one of the things that is in the iterable, 38 00:02:44,230 --> 00:02:47,220 one of the things that's in T. So, 39 00:02:47,220 --> 00:02:50,590 in this case, Z will be a string. 40 00:02:56,210 --> 00:03:01,610 What will be the type of my iterator variable on the first iteration? 41 00:03:01,610 --> 00:03:06,920 So, Z will be bound to nine on the first iteration. 42 00:03:06,920 --> 00:03:09,570 So, Z will be an integer. 43 00:03:14,000 --> 00:03:16,695 So, I think you get the idea here. 44 00:03:16,695 --> 00:03:20,820 I'm really just trying to reinforce the vocabulary. 45 00:03:20,820 --> 00:03:24,940 The iterable is the sequence. 46 00:03:26,420 --> 00:03:29,350 It's the thing that you iterate through, 47 00:03:29,350 --> 00:03:32,400 its a thing that goes after the word N. 48 00:03:32,620 --> 00:03:41,330 The iterator variable is 49 00:03:41,330 --> 00:03:44,620 the variable name between the word for and the word in, 50 00:03:44,620 --> 00:03:48,545 and it will be bound each time to one item from the iterable, 51 00:03:48,545 --> 00:03:50,820 one item from the sequence. 52 00:03:51,560 --> 00:03:53,865 So, don't get confused. 53 00:03:53,865 --> 00:03:57,425 The iterable is a thing that you iterate through, goes after the in. 54 00:03:57,425 --> 00:04:00,320 The iterator variable is the thing that's bound to 55 00:04:00,320 --> 00:04:05,040 each item in the sequence. We'll see you next time.