一些外部代码运行以下代码的我的功能:
def __init__(self,weights=None,threshold=None):
print "weights: ", weights
print "threshold: ", threshold
if weights:
print "weights assigned"
self.weights = weights
if threshold:
print "threshold assigned"
self.threshold = threshold
这段代码输出:
weights: [1, 2]
threshold: 0
weights assigned
即打印运算符的行为就像threshold
是零,而if
运算符的行为就像它没有定义一样。
正确的解释是什么?怎么了?参数的状态是什么threshold
,如何识别?