[Tutor] An identity question

Kent Johnson kent37 at tds.net
Sun Apr 22 21:13:39 CEST 2007


Cecilia Alm wrote:
> The differences in cases 1 and 3 vs. 2 is due to 'common values' of
> name assignments being treated a bit differently, right? Also, it's
> clear why case 5 evaluates to false.  But, why does the case 4
> equality check evaluate to True, whereas case 1 and 3 don't?
> 
> case 4:
>>>> def foo():
> ...     x = 10000
> ...     return x
> ...
>>>> A = foo()
>>>> B = foo()
>>>> A is B
> True

I think in this case foo() has an internal reference to the constant 
10000. It returns the same reference each time.

Kent


More information about the Tutor mailing list