- python中的构造方法
__new__(cls,*args,**kwargs):必须有返回值,是类方法
__init__():此为初始化方法
- mro(),可以看到所有父类,即搜索顺序
@classmethod 类方法
__method__(class)
- 单例
Class SingleTone:
__instance=None
def __new__(cls):
if cls.__instance==None:
cls.__instance=object.__new__(cls)
return cls.__instance
else:
扫描二维码关注公众号,回复:
1460678 查看本文章
return cls.__instance
s=SingleTone()
ss=SingleTone()
print(id(s),id(ss))
- 异常
try:
语句体
Except:
异常
或
Try:
语句体
Except(异常类型1,异常类型2):
except Exception:
所有异常
或
Try:
Except 异常类型 as 名称:
Print(名称)
Else