class Singleton:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
# 这里可以添加初始化代码
return cls._instance
# 使用Singleton类
instance1 = Singleton()
instance2 = Singleton()
# instance1 和 instance2 是同一个实例
assert instance1 is instance2