单例模式

class SingleTon:
    _instance = None

    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = super().__new__(cls, *args, **kwargs)
        return cls._instance


s1 = SingleTon()
s2 = SingleTon()
print(s1 is s2)

你可能感兴趣的:(单例模式)