单例模式

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>
posted @ 2019-12-24 17:59  疯狂列表推导式  阅读(106)  评论(0编辑  收藏  举报