Challenge - 5 Problems
Identity Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of identity comparison with small integers
What is the output of this code snippet?
Python
a = 256 b = 256 print(a is b)
Attempts:
2 left
💡 Hint
Small integers are cached by Python, so identical values share the same object.
✗ Incorrect
Python caches small integers from -5 to 256, so variables with the same value in this range point to the same object, making 'is' return True.
❓ Predict Output
intermediate2:00remaining
Identity comparison with lists
What is the output of this code?
Python
list1 = [1, 2, 3] list2 = [1, 2, 3] print(list1 is list2)
Attempts:
2 left
💡 Hint
Two lists with the same content are different objects in memory.
✗ Incorrect
Even if two lists have the same content, they are different objects, so 'is' returns False.
🧠 Conceptual
advanced2:00remaining
Understanding 'is not' with None
Which option correctly checks if variable x is not None?
Attempts:
2 left
💡 Hint
Use identity operators to check against None.
✗ Incorrect
The correct way to check if x is not None is using 'is not None'. Using '!=' works but is not recommended for identity checks.
❓ Predict Output
advanced2:00remaining
Output of identity comparison with strings
What is the output of this code?
Python
s1 = 'hello world' s2 = 'hello world' print(s1 is s2)
Attempts:
2 left
💡 Hint
Strings with spaces may not be interned automatically.
✗ Incorrect
Python may not intern strings with spaces automatically, so s1 and s2 are different objects, making 'is' return False.
🔧 Debug
expert2:00remaining
Identify the error in identity operator usage
Which option will cause a SyntaxError when using identity operators?
Attempts:
2 left
💡 Hint
Check the correct syntax for 'is not' operator.
✗ Incorrect
'is not' is two separate words. 'is!' is invalid syntax and causes SyntaxError.