python類 析構方法


對象被銷毀時執行的操作。一般用於資源回收。Python有垃圾回收機制會自動調用__del__,也可自己調用。

# -*- coding: UTF-8 -*-
class Student:
    company = 'LOL'
    def __del__(self):
    print("銷毀對象{0}".format(self))

s1 = Student()
s2 = student()
del s1

"銷毀對象"s1和s2都會被調用,s2有回收機制調用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM