定义:保证一个类只能有一个具体的实例,并提供一个访问它的全局访问点
使用场景:当一个类只能有一个实例,而客户可以从一个众所周知的访问点访问它时
class StrTools:
pass
str_tool = StrTools()
from tool import str_tool
s1 =str_tool
s2 =str_tool
print(id(s1))
print(id(s2))
定义:保证一个类只能有一个具体的实例,并提供一个访问它的全局访问点
使用场景:当一个类只能有一个实例,而客户可以从一个众所周知的访问点访问它时
class StrTools:
pass
str_tool = StrTools()
from tool import str_tool
s1 =str_tool
s2 =str_tool
print(id(s1))
print(id(s2))