對列表的修改

papering發表於2024-06-17
class T:
def __init__(self):
self.lst = []
# biz
for i in range(6):
self.lst.append(i)

def f(self, i):
print(i)
if i in self.lst:
self.lst.remove(i)

def __del__(self):
for i in self.lst:
self.f(i)


t = T()

修復:

class T:
def __init__(self):
self.lst = []
# biz
for i in range(6):
self.lst.append(i)

def f(self, i):
print(i)
if i in self.lst:
self.lst.remove(i)

#
# def __del__(self):
# for i in self.lst:
# self.f(i)

def __del__(self):
for i in [i for i in self.lst]:
self.f(i)


t = T()

相關文章