__del__函数

Searching…

zhuanlan.zhihu.com

Python魔法方法之__init__、__del__与__new__ - 知乎

2. __del__ (self) 同__init__方法相反,__del__在对象销毁时被调用,往往用于清除数据或还原环境等操作,比如在类中的其他普通方法中实现了插入数据库的语句,当对象被销毁时我们需要将数据还原,那么这时可以在__del__方法中实现还原数据库数据的功能。

blog.csdn.net

Python __del__使用教程:释放对象的终极秘籍_python...

Jun 28, 2025 · 这种资源可以是内存、文件句柄或其他外部资源。 为了实现这一目的,Python提供了特殊方法__del__,它允许我们在对象被销毁之前执行一些清理操作。 本文将详细介绍Python __del__的使用教程,帮助你理解和充分利用这一强大的特性。

www.geeksforgeeks.org

What is __del__ in Python? - GeeksforGeeks

Jul 23, 2025 · The __del__ method in Python is a powerful tool for managing resource cleanup when objects are destroyed. It allows you to define specific actions that should be taken when an object is garbage collecte...

cloud.tencent.com

Video — click to view

Aug 7, 2025 · 什么是析构函数? 析构函数 (Destructor)是面向对象编程中的一个特殊方法,它在对象被销毁时自动调用。 在 Python 中,析构函数的名称为 __del__ ()。 当Python对象的引用计数降为零时,或者当垃圾回收器回收对象时,Python会自动调用该对象的 __del__ 方法。

blog.csdn.net

python的__del__ ()方法_python del对象时触发-CSDN博客

Sep 24, 2025 · def __del__(self): print("__del__方法被调用") print("%s对象马上被干掉了..."%self.__name) # 创建对象 dog = Animal("哈皮狗") # 删除对象 del dog cat = Animal("波斯猫") cat2 = cat cat3 = cat print("---马上 删除cat对象") del cat print("---马...

www.geeksforgeeks.org

Python : __delete__ vs __del__ - GeeksforGeeks

Jul 12, 2025 · Both __delete__ and __del__ are dunder or magic methods in Python. Dunder or magic methods in Python are the methods having two prefix and suffix underscores in the method name.