python "is" equivalency is confusing for some mutable objects

36 Views Asked by At

this is the first time i'm asking a question; i apologise in advance for any mistakes i may make out of ignorance;

here's my question: why do i get "False" for any equivalence of mutable objects using 'is' while they seem to point at the same memory location?

>>> 1 is 1
True
>>> "a" is "a"
True
>>> 'b' is 'b'
True
>>> () is ()
True
>>> [] is []
False
>>> {} is {}
False
>>> print(id({}), id({}))
(140262895310280, 140262895310280)
>>> print(id([]), id([]))
(140262895262032, 140262895262032)
>>> print(id(()), id(()))
(140262896386128, 140262896386128)```
0

There are 0 best solutions below