Remembering That Not All 'Ins' Are Alike
00:00
Not all in
are alike. As you’ve just seen in the previous lesson, you may encounter in
in different contexts in Python. Specifically, you’re looking at membership testing in this case.
00:11
But then you’ve also seen in
when you are iterating over elements, so inside of a for
loop. Now let’s just look at those in the REPL for a moment.
00:20
So in this course you primarily see in
used in a membership check. So that would be 1 in the tuple (1, 2, 3)
, for example, that returns True
.
00:31
This is a membership check, but just previously, you’ve also seen it inside a for
loop. So you could do something like for number
and let’s work with the same tuple as before (1, 2, 3)
,
00:46
and then you can do something with each element in that iterable. So here I can print(number)
for example.
00:53
While this looks the same, here’s an in
and here’s an in
. This is two different use cases. They’re not related. So if you see an in
inside of a for
loop, then it doesn’t have anything to do with membership checking.
01:04
This is about iteration and this is the specific construct that Python uses to iterate over a sequence. Membership checking is only if you see in
or not in
in a construct that looks like this and the ones that you’ve previously seen as well.
01:18
This lesson is just meant as a quick little reminder that not all ins
in Python are alike.
Become a Member to join the conversation.