class Singlen(object): _inten = None def __new__(cls, *args, **kwargs): if not cls: # 判断实例是否存在,不存在就新建实例 cls._inten = object.__new__(cls) return cls._inten a = Singlen(1) b = Singlen(2) print(id(a),id(b))
单例模式
最新推荐文章于 2024-08-30 12:42:13 发布
class Singlen(object): _inten = None def __new__(cls, *args, **kwargs): if not cls: # 判断实例是否存在,不存在就新建实例 cls._inten = object.__new__(cls) return cls._inten a = Singlen(1) b = Singlen(2) print(id(a),id(b))