LaundroMat
Programmer
I don't understand why this code
results in
It appears by calling another classes method, the list is shared?
Code:
class player:
name = ''
hand = []
def __init__(self, name=""):
self.name = name
class test:
def addItem(self, recipient, item):
recipient.hand.append(item)
def main():
me = player("LaundroMat")
him = player("Someone else")
t = test()
t.addItem(me, "Apple")
print him.hand
if __name__ == "__main__":
main()
results in
Code:
['Apple']
It appears by calling another classes method, the list is shared?