【发布时间】:2017-06-20 13:50:48
【问题描述】:
我想知道为什么逗号符号“,”返回true:
mutant = toolbox.clone(ind1)
ind2, = tools.mutGaussian(mutant, mu=0.0, sigma=0.2, indpb=0.2)
print (ind2 is mutant)
>>>True
但是当我删除逗号符号时:
ind2 = tools.mutGaussian(mutant, mu=0.0, sigma=0.2, indpb=0.2)
print (ind2 is mutant)
>>>False
它返回假。 如果有人能解释这背后的机制,将非常感激。
【问题讨论】:
-
您正在将包含一个元素的可迭代对象分配给名称的元组。
-
换句话说,在您的第二个版本中,
ind2[0] is mutant将起作用。 -
只需输入
ind2以查看变量在每种情况下的确切含义。您会看到它是两个相似但不同的值。 -
来自
mutGaussian()documentation:返回:一个人的元组。 -
感谢提醒,区别在于列表和元组。