[Tutor] pointer puzzlement

Jim Mooney Py3.4.3winXP cybervigilante at gmail.com
Thu May 7 21:15:42 CEST 2015


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?

def testid(K=10):
    K += 10
    return 'the ID is', id(K), K

*** Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600
32 bit (Intel)] on win32. ***
>>> testid()
('the ID is', 505991936, 20)
>>> testid()
('the ID is', 505991936, 20)
>>> testid()
('the ID is', 505991936, 20)
>>>

-- 
Jim


More information about the Tutor mailing list