Explanation of list reference
rosuav at gmail.com
Sat Feb 15 01:57:33 CET 2014
On Sat, Feb 15, 2014 at 8:43 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Unfortunately neither the "everything is a reference" model nor the
> "small/big" model help you predict the value of an "is" operator in the
> ambiguous cases.
Can you give an example of an ambiguous case? Fundamentally, the 'is'
operator tells you whether its two operands are exactly the same
object, nothing more and nothing less, so I assume your "ambiguous
cases" are ones where it's possible for two things to be either the
same object or two indistinguishable ones.
The only situation I can think of is that immutables are allowed to be
interned, which is why this comes up True (in CPython) when it would
come up False with larger values (as I demonstrated earlier):
>>> x = 1
>>> y = 2
>>> z = x + y
>>> z is 3
More information about the Python-list