0
0
Pythonprogramming~5 mins

Membership operators (in, not in) in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ATrue
BFalse
CError
DNone
What is the result of 'x' not in 'example'?
ATrue
BFalse
CError
DNone
Which operator checks if an item is NOT in a sequence?
Anot in
Bin
C==
D!=
What does 'key' in {'key': 1, 'val': 2} check?
AIf 'key' is a value
BIf 'key' is a string
CIf 'key' is a list
DIf 'key' is a key
What is the output of 10 not in (5, 10, 15)?
AError
BTrue
CFalse
DNone
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.