S
Sean McIlroy
hi all
when i run this code in python 2.3
###################### BEGIN CODE
class warfare:
def __init__(self): self.pairs = [[0,0]]*2
def __str__(self): return str(self.pairs)
def setfirst (self,i,value): self.pairs[0] = value
def setsecond(self,i,value): self.pairs[1] = value
w = warfare()
print w
w.setfirst(0,'hello')
print w
###################### END CODE
i get this result
###################### BEGIN ACTUAL RESULT
[[0, 0], [0, 0]]
[['hello', 0], ['hello', 0]]
###################### END ACTUAL RESULT
instead of the expected result
###################### BEGIN EXPECTED RESULT
[[0, 0], [0, 0]]
[['hello', 0], [0, 0]]
###################### END EXPECTED RESULT
is there a reasonable explanation for this behavior?
peace
stm
when i run this code in python 2.3
###################### BEGIN CODE
class warfare:
def __init__(self): self.pairs = [[0,0]]*2
def __str__(self): return str(self.pairs)
def setfirst (self,i,value): self.pairs[0] = value
def setsecond(self,i,value): self.pairs[1] = value
w = warfare()
print w
w.setfirst(0,'hello')
print w
###################### END CODE
i get this result
###################### BEGIN ACTUAL RESULT
[[0, 0], [0, 0]]
[['hello', 0], ['hello', 0]]
###################### END ACTUAL RESULT
instead of the expected result
###################### BEGIN EXPECTED RESULT
[[0, 0], [0, 0]]
[['hello', 0], [0, 0]]
###################### END EXPECTED RESULT
is there a reasonable explanation for this behavior?
peace
stm