python中的单例模式
"""
单例模式
1. 类方法实现
2. new方法实现
3. 元类方法实现(推荐)
"""
# 示例
class Test(object):
def __new__(cls, *args, **kwargs):
return "Hello World"
t = Test()
print(t) # Hello World
"""
1. 类方法实现
"""
class Test(object):
__instance = Non
原创
2021-10-18 14:15:32 ·
155 阅读 ·
0 评论