1. 三元表达式: if else
is_fat = True
state = "fat" if is_fat else "not fat"
2. try except
try:
1/0
except Exception as e:
# 访问异常的错误编号和详细信息
print(e.args)
print(str(e))
print(repr(e))
if not os.path.isfile(yaml_file):
raise Exception('yaml config {} does not exist'.format(yaml_file))
3. if or :
if name_Current == '下季' or name_Current == '隔季'::
t_cut1 = t_cut1 * t_month
elif name_Current == '当月' or name_Current == '下月':
t_cut1 = t_cut1
print('月度修正, 当月/下月')
else:
raise Exception('wrong type')
4. 将True/False 转为1 /-1
signal_bottom = (z_score < z_score_min).astype('int')