大家好,给大家分享一下python简单有趣的程序源代码,很多人还不知道这一点。下面详细解释一下。现在让我们来看看!
火车头采集ai伪原创插件截图:
先选取了 6 个自己认为值得玩味的 python 代码,希望对正在学习 python 的你有所帮助。
1、类有两个方法,一个是 __new__,一个是 __init__,有什么区别,哪个会先执行呢?
class test(object): def __init__(self): print("test -> __init__") def __new__(cls): print("test ->__new__") return super().__new__(cls) a = test() 复制代码
运行结果如下:
test ->__new__ test -> __init__ 复制代码
再来看另一个例子
class test2(object): def __init__(self):