is — Expert Playground
Identity operator; tests whether two variables reference the same object
Python Playground
Output
Click "Run" to execute your code'is' compiles to IS_OP which is a simple pointer comparison (O(1)). '==' compiles to COMPARE_OP which calls __eq__ and may be arbitrarily slow. 'is not' is a single opcode, not 'not' applied to 'is'.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?