一些代碼從我的pygame遊戲中複製(並修改)。但同樣的問題發生,我不明白。爲什麼background_pos_init輸出在列表中是不同的,而且它是一個整數或字符串?爲什麼輸出不是一個列表,int或字符串?
class Player():
def __init__(self):
self.pos_init = [16]
self.pos = self.pos_init
class Window():
def __init__(self):
self.background_pos_init = [0]
self.background_pos = self.background_pos_init
def moveBackground(self):
self.background_pos[0] = self.background_pos_init[0] + player.pos[0]
print(self.background_pos)
print(self.background_pos_init)
player = Player()
window = Window()
window.moveBackground()
給出了輸出:
============== RESTART: C:\Users\SAMP\Documents\Python\test.py ==============
[16]
[16]
>>>
和
class Player():
def __init__(self):
self.pos_init = 16
self.pos = self.pos_init
class Window():
def __init__(self):
self.background_pos_init = 0
self.background_pos = self.background_pos_init
def moveBackground(self):
self.background_pos = self.background_pos_init + player.pos
print(self.background_pos)
print(self.background_pos_init)
player = Player()
window = Window()
window.moveBackground()
給出了輸出:
============== RESTART: C:\Users\SAMP\Documents\Python\test.py ==============
16
0
如果我改變價值觀,以 '海峽',輸出是:
============== RESTART: C:\Users\SAMP\Documents\Python\test.py ==============
strstr
str