Recall & Review
beginner
What does the
in operator check in Python?The
in operator checks if a value exists inside a sequence like a list, string, or tuple. It returns True if the value is found, otherwise False.Click to reveal answer
beginner
How does the
not in operator work?The
not in operator checks if a value does NOT exist in a sequence. It returns True if the value is missing, otherwise False.Click to reveal answer
beginner
Example: What is the output of
'a' in 'cat'?The output is
True because the letter 'a' is found inside the string 'cat'.Click to reveal answer
beginner
Example: What does
5 not in [1, 2, 3, 4] return?It returns
True because the number 5 is not present in the list.Click to reveal answer
intermediate
Can membership operators be used with dictionaries?
Yes, membership operators check keys in dictionaries. For example,
'key' in dict checks if 'key' is a key in the dictionary.Click to reveal answer
What does
3 in [1, 2, 3, 4] return?✗ Incorrect
3 is present in the list, so
3 in [1, 2, 3, 4] returns True.What is the result of
'x' not in 'example'?✗ Incorrect
The letter 'x' is in 'example', so
'x' not in 'example' returns False.Which operator checks if an item is NOT in a sequence?
✗ Incorrect
The
not in operator checks if an item is missing from a sequence.What does
'key' in {'key': 1, 'val': 2} check?✗ Incorrect
Membership operators check keys in dictionaries, so it checks if 'key' is a key.
What is the output of
10 not in (5, 10, 15)?✗ Incorrect
10 is in the tuple, so
10 not in (5, 10, 15) returns False.Explain how the
in and not in operators work in Python with examples.Think about checking if something is inside or outside a group.
You got /3 concepts.
Describe how membership operators behave when used with dictionaries.
Remember dictionaries have keys and values.
You got /3 concepts.