python 也有析构函数, 我震惊了。

class Car(object):
    def __init__(self):
        print '---ok---'

    def __del__(self):
        print '----deconstrcut-------'


c =  Car()


执行结果

---ok---
----deconstrcut-------


这确实证明了析构函数被执行了,以后看来,有些逻辑可以放在析构函数中。

参考文档

https://docs.python.org/2/reference/datamodel.html


你可能感兴趣的:(python)