class Test(object): __instance = None def __init__(self): print("----init方法----") def __new__(cls): print("----new方法----") if cls.__instance == None: cls.__instance = object.__new__(cls) return cls.__instance
test1 = Test()
print(id(test1))
test2 = Test()
print(id(test2))
#单例模式id值是一样的