标签:rgs new 单例模式 __new__ war turn code main ret
class Demo(object):
__instance = None
def __new__(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = object.__new__(cls)
return cls.__instance
else:
return cls.__instance
A = Demo()
B = Demo()
print(A)
print(B)
# <__main__.Demo object at 0x1037fd8d0>
# <__main__.Demo object at 0x1037fd8d0>
标签:rgs new 单例模式 __new__ war turn code main ret
原文地址:https://www.cnblogs.com/hui-code/p/12092847.html