0
這是代碼:的append()函數的行爲出現異常
import random
mylist=[]
position=[300,300]
while 1:
randomint = random.randint(1,3)
print mylist
if randomint == 3:
position[0]+=5
mylist.append(position)
,而是這個:
[]
[[305, 300], [310, 300]]
[[305, 300], [310, 300], [315, 300]]
[[305, 300], [310, 300], [315, 300]]
[[305, 300], [310, 300], [315, 300]]
... 我得到這個:
[]
[[305, 300]]
[[305, 300]]
[[305, 300]]
[[305, 300]]
[[305, 300]]
[[305, 300]]
[[310, 300], [310, 300]]
[[315, 300], [315, 300], [315, 300]]
[[315, 300], [315, 300], [315, 300]]
[[315, 300], [315, 300], [315, 300]]
[[315, 300], [315, 300], [315, 300]]
[[315, 300], [315, 300], [315, 300]]
[[315, 300], [315, 300], [315, 300]]
[[315, 300], [315, 300], [315, 300]]
[[315, 300], [315, 300], [315, 300]]
[[320, 300], [320, 300], [320, 300], [320, 300]]
...
爲什麼?這很奇怪,不是嗎?