0
0
Pythonprogramming~20 mins

Membership operators (in, not in) in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Membership Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Check membership in a list
What is the output of this code?
Python
fruits = ['apple', 'banana', 'cherry']
result = 'banana' in fruits
print(result)
ATrue
BFalse
CSyntaxError
DNone
Attempts:
2 left
💡 Hint
Remember, 'in' checks if an item exists inside a list.
Predict Output
intermediate
2:00remaining
Check membership in a string
What is the output of this code?
Python
text = 'hello world'
result = 'z' not in text
print(result)
ATrue
BFalse
CTypeError
DSyntaxError
Attempts:
2 left
💡 Hint
The 'not in' operator returns True if the item is not found.
Predict Output
advanced
2:00remaining
Membership check with dictionary keys
What is the output of this code?
Python
data = {'a': 1, 'b': 2, 'c': 3}
result = 'b' in data
print(result)
AFalse
BTrue
CKeyError
DTypeError
Attempts:
2 left
💡 Hint
Membership in a dictionary checks keys, not values.
Predict Output
advanced
2:00remaining
Membership check with a tuple
What is the output of this code?
Python
t = (10, 20, 30, 40)
result = 25 not in t
print(result)
AFalse
BTypeError
CTrue
DSyntaxError
Attempts:
2 left
💡 Hint
The 'not in' operator returns True if the item is not found in the tuple.
🧠 Conceptual
expert
3:00remaining
Understanding membership with nested lists
Given the code below, what is the output?
Python
nested = [[1, 2], [3, 4], [5, 6]]
result = [3, 4] in nested
print(result)
AFalse
BTypeError
CSyntaxError
DTrue
Attempts:
2 left
💡 Hint
Membership checks for the exact item in the list, including nested lists.