所以我很好奇,可以說我有一個類如下什麼時候我應該在Python中使用del?
class myClass:
def __init__(self):
parts = 1
to = 2
a = 3
whole = 4
self.contents = [parts,to,a,whole]
有加線
del parts
del to
del a
del whole
在構造函數中或將這些變量的內存範圍進行管理的任何benifit ?
沒有。只要構造函數返回,解釋器就會自動釋放一旦超出範圍的變量。 'del'很少有用。 –
從來沒有,垃圾收集 – PYPL
相關:http://stackoverflow.com/questions/34430314/python-lifetime-memory-scope-of-local-variables-inside-a-function –