An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right.
如果要在不使用iterable赋值的情况下测试该单个值,则必须手动从元组中获取该值:
ind2 = tools.mutGaussian(mutant, mu=0.0, sigma=0.2, indpb=0.2)
print(ind2[0] is mutant)
当您用逗号声明或分配变量时,您正在创建一个tuple。在
您正在调用的^{} function 返回一个包含单个值的元组:
如果不使用逗号,则将生成的元组分配给单个变量。在
使用逗号,可以要求Python将右侧的iterable解压为左侧的一系列名称;因为左侧和右侧都只有一个元素,所以这样做是可行的。您将返回的元组中的值解压到单个变量中。在
请参见Assignment statements reference documenation:
如果要在不使用iterable赋值的情况下测试该单个值,则必须手动从元组中获取该值:
注意
[0]
索引。在相关问题 更多 >
编程相关推荐