[問題] Class內使用list的問題
各位大大好
請問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]
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.44.75.200 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1618243395.A.F6C.html
→
04/13 00:14,
3年前
, 1F
04/13 00:14, 1F
推
04/13 00:55,
3年前
, 2F
04/13 00:55, 2F
→
04/13 00:56,
3年前
, 3F
04/13 00:56, 3F
推
04/13 08:07,
3年前
, 4F
04/13 08:07, 4F
→
04/13 08:07,
3年前
, 5F
04/13 08:07, 5F
→
04/13 10:28,
3年前
, 6F
04/13 10:28, 6F