我按照以下方式构建了Singleton:
class Singleton:
_instance = None
def __new__(cls):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance
def __init__(self, a):
self.a = a
当我创建实例时
first = Singleton(3)
second = Singleton(6)
并称为
first.a # ouput: 6
期望输出
first.a # output 3
我不知道为什么?