If the target list is a comma-separated list of targets, or a single target in square brackets: The object must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets.
这是一个非常有趣的问题,尽管我首先要说的是,您不应该在每行中为同一个变量赋值超过一次。在
第一个示例期望
load_data()
返回两个元组。它将把(x, _)
分配给第一个。下划线是用于解压缩不关心的值的约定。当第二个元组被解包时,它将被覆盖。在它将把load2()返回的元组加载到您定义的变量x、y和uu中。这又将把每个元组的第一个成员赋给x和y,最后一个值赋给
_
变量(在第二次调用时被重写)。在示例:
输出
documentation on assignment statements的相关部分是:
(强调我的意思:顺序就是这样确定的。)
相关问题 更多 >
编程相关推荐