美文网首页
12.Python中的设计模式

12.Python中的设计模式

作者: 橙子只涩不酸 | 来源:发表于2018-06-14 17:24 被阅读0次

    1.单例模式

    class Dog(object):

         __instance=None

         def __new__(cls):

             if cls.__instance==None:

                cls.__instance = object.__new__(cls)

                return cls.__instance

             else:

                 return cls.__instance

     a = Dog()

     print(id(a))#查看实例对象指向的地址值

    b = Dog()

     print(id(b))

    相关文章

      网友评论

          本文标题:12.Python中的设计模式

          本文链接:https://www.haomeiwen.com/subject/gfgyeftx.html