1.单例模式
class Dog(object):
__instance=None
def __new__(cls):
if cls.__instance==None:
cls.__instance = object.__new__(cls)
return cls.__instance
else:
return cls.__instance
a = Dog()
print(id(a))#查看实例对象指向的地址值
b = Dog()
print(id(b))
class Dog(object):
__instance=None
def __new__(cls):
if cls.__instance==None:
cls.__instance = object.__new__(cls)
return cls.__instance
else:
return cls.__instance
a = Dog()
print(id(a))#查看实例对象指向的地址值
b = Dog()
print(id(b))