[Tutor] variable assignment

Poor Yorick gp@pooryorick.com
Fri Jan 3 01:17:01 2003


  In the following code, I halfway expected the final print statement to 
produce the same number the other three print statements produced, but 
it did not.  Could anyone explain why?

class one:
    def __init__(self):
        self.d = 'hello'
    def Get(self):
        return self.d

class two:
    def __init__(self):
        self.d = {1: 'hello'}
    def Get(self):
        return self.d[1]

ins1 = one()
var = ins1.Get()
print id(var[1])
print id(ins1.d[1])

ins2 = two()
var2 = ins2.Get()
print id(var2[1])
print id(ins2.d[1])


poor yorick
gp@pooryorick.com