Testing for Membership
Consider you want to determine if an item is in a particular collection or not. In Python, you use the
in operator to do that. So if you create a list of numbers, you can see that
3 is in it, and
5 is not.
Here’s another example of membership based on something you saw before. Recall using
and to see if a number was in a particular range. But Python has a
range() function to generate the collection of integers in a range. So you can use the
in operator to test for that.
Become a Member to join the conversation.