首页 > 解决方案 > 什么是 x, y = func(x, y)

问题描述

我对python很陌生。在我看到的一个教程(关于 Tensorflow)中,我鼓励了这种奇怪的符号,这是我在任何其他语言中从未见过的。

那么有人可以解释一下这是做什么的吗?

train_labels, train_samples = shuffle(train_labels, train_samples)

或者

一般是什么x, y = function(x, y)意思。

标签: python

解决方案


x, y = function(x, y)用于元组解包。当您调用的函数返回 2 个或更多值时,它会将第一个值分配给 x,将第二个值分配给 y,依此类推。请参阅下面的示例

def function():
   return 3, 4

x, y = function()

# x will be set to 3
# y will be set to 4

推荐阅读