单例对象

单例对象:

每次调用都是同一个对象

单例对象的创建

class Dog(object):
    __instance = None
    
    def __new__(cls):
        if cls.__instance == None:
            cls.instance = object.__new__(cls)
            return cls.__instance
    else:
        return cls.__instance

  

 

posted @ 2018-08-24 14:17  zmwzmw  阅读(71)  评论(0编辑  收藏  举报