class Dog(object):
__instance = None def __init__(self):
pass def __new__(cls):
if not cls.__instance:
cls.__instance = object.__new__(cls)
return cls.__instance d = Dog()
dd = Dog()
#d和dd的id相同
print(id(d))
print(id(dd))
05-15 04:50