class SingleObj(): __singleobj=None @classmethod def get_singleinstance(cls): if not cls.__singleobj: cls.__singleobj=SingleObj() return cls.__singleobj obj1=SingleObj.get_singleinstance() print(obj1) obj2=SingleObj.get_singleinstance() print(obj2) obj3=SingleObj.get_singleinstance() print(obj3) ##ret <__main__.SingleObj instance at 0x00000000057B1E88> <__main__.SingleObj instance at 0x00000000057B1E88> <__main__.SingleObj instance at 0x00000000057B1E88>