Reply:

Reply:

Sherzod Akhmedov

They are completely differentis checks for object identity, while == checks for equality (a notion that depends on the two operands' types).


It is only a lucky coincidence that "is" seems to work correctly with small integers (e.g. 5 == 4+1). That is because Python optimizes the storage of integers in the range (-5 to 256) by making them singletons. This behavior is totally implementation-dependent and not guaranteed to be preserved under all manner of minor transformative operations.

Example #1
Example #2


Report Page