[Tutor] pointer puzzlement

Dave Angel davea at davea.name
Fri May 8 01:48:29 CEST 2015


On 05/07/2015 04:03 PM, Emile van Sebille wrote:
> On 5/7/2015 12:15 PM, Jim Mooney Py3.4.3winXP wrote:
>> I find this a bit confusing. Since the ID of K remains the same, so it's
>> the same object, why isn't it increasing each time. i.e, 20, 30, 40,. I
>> understand that it's immutable but doesn't that mean K is created each
>> time
>> in local scope so it should have a different ID each time?
>
> You're looking at the ID of an interned string:

Interned int

>
>  >>> testid()
> ('the ID is', 7515584L, 20)
>  >>> testid()
> ('the ID is', 7515584L, 20)
>  >>> testid()
> ('the ID is', 7515584L, 20)
>  >>> id(20)
> 7515584L
>  >>> id(10+10)
> 7515584L
>  >>> id(19+1)
> 7515584L
>
>
> Compare to:
>
> def testid(K=1000000):
>       K += 10
>       return 'the ID is', id(K), K
>
>


-- 
DaveA


More information about the Tutor mailing list