Python:对象的生命周期new-init-call-del
2023-09-14 09:07:15 时间
对象的生命周期:
创建、初始化、使用、垃圾回收
代码示例
# -*- coding: utf-8 -*-
class Demo(object):
# 创建 反回 类的实例对象
def __new__(cls, *args, **kwargs):
print("__new__")
return super(Demo, cls).__new__(cls, *args, **kwargs)
# 初始化 只能反回 None
def __init__(self):
print("__init__")
# 使用
def __call__(self, *args, **kwargs):
print("__call__")
# 垃圾回收
def __del__(self):
print("__del__")
if __name__ == '__main__':
demo = Demo()
demo()
"""
__new__
__init__
__call__
__del__
"""
相关文章
- Python version 2.7 required, which was not found in the registry
- 在Python中定义和使用抽象类的方法
- [Python] numpy fillna() for Dataframe
- python 判断一个对象是可迭代对象
- Python json使用实例:字符串与对象互转代码示例
- paip.python错误解决 "0x64024e96" 指令引用的 "0x00000135" 内存。该内存不能为 "read"。
- 100天精通Python(数据分析篇)——第54天:Pandas之Series对象基础大总结
- Python每日一练(数据分析篇)——第36天:中位函数
- python将图片转为矢量图
- 一文讲全了Python 类和对象内容
- python字典转对象
- marshmallow: 简化Python对象系列化
- 【华为机试真题 Python实现】字符串统计
- Python编程:获取一个类对象的属性和方法
- 【Android 逆向】使用 Python 代码解析 ELF 文件 ( PyCharm 中进行断点调试 | ELFFile 实例对象分析 )
- python 使用函数参数注解
- python里使用await关键字来等待Future对象完成
- python里使用Condition对象来唤醒指定数量的协程
- python web py入门(42)- 函数的集合--jquery库
- python基础===用9种方式生成新的对象
- python对象销毁(垃圾回收)
- 第28讲:Python中字典对象的核心概念以及使用案例
- win10 安装python-nmap