作者:
xb1015 (Marco)
2021-04-13 00:03:13各位大大好
請問class內是否可以各個物件使用各自的list呢?
我發現 two.thelist 會出現'10',但是實際append在one
請問原因是什麼呢?
要如何各自使用各自的list呢?(one & two 擁有不同的thelist)
請大大指點迷津! 感激不盡~
e.g.
class class1():
theint = -1
thelist=[]
def __init__(self, A, B):
print(A)
self.theint = A
self.thelist.append(B)
one = class1(123)
two = class1(456)
one.thelist.append(10)
one.thelist
>> Out: [456, 789, 10]
two.thelist
>> Out: [456, 789, 10]