我遇到了如下代码:
def plot_svc(model, ax=None, plot_support=True):
"""function to plot 2-D SVC"""
if ax is None:
ax=plt.gca()
如果我们要设置默认参数,ax=None
为什么要使用if语句,我们不知道那ax
是None
吗?所以我们不能只写:
def plot_svc(model, ax=None, plot_support=True):
"""function to plot 2-D SVC"""
ax=plt.gca()
谢谢!
因为在调用函数时ax可能不为None。
def f(x=None):
if x is None:
return True
return False
>>> f(None)
True
>>> f()
True
>>> f(3)
False
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句