python 安全除法

python 安全除法 def safe_div(n, d, as_pctFalse) - float:“”“安全除法d0 返回 0as_pctTrue 时返回 *100 的百分比数值”“”n 0 if n is None or (isinstance(n, float) and np.isnan(n)) else nd 0 if d is None or (isinstance(d, float) and np.isnan(d)) else dif d 0:return 0.0v n / dreturn v * 100.0 if as_pct else v