单例模式

class Person(object):
    instance = None

    def __new__(cls, *args, **kwargs):

        if cls.instance is None:
            cls.instance = super().__new__(cls)

        return cls.instance

    def __init__(self):
        print('我是init')


p1 = Person()
p2 = Person()
p3 = Person()
print(p1)
print(p2)
print(p3)

 

posted on 2020-03-13 16:38  沈家大大  阅读(99)  评论(0编辑  收藏  举报