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:
>>> 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
Emile
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor