python - 什么是 x, y = func(x, y)
问题描述
我对python很陌生。在我看到的一个教程(关于 Tensorflow)中,我鼓励了这种奇怪的符号,这是我在任何其他语言中从未见过的。
那么有人可以解释一下这是做什么的吗?
train_labels, train_samples = shuffle(train_labels, train_samples)
或者
一般是什么x, y = function(x, y)
意思。
解决方案
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
推荐阅读
- mysql - 如何手动将csv导入mysql
- sql - sql bigquery中rank()时的重复数据
- javascript - 如何防止用户在 ReactJS 的输入表单字段中输入空格?
- c# - 实体框架:WillCascadeOnDelete 和 Include
- html - 如何在react js web中实现下拉或列表中的多选项目
- angular - 可拖动的 ngx-bootstrap 模态只有身体移动和背景固定
- javascript - Flexbox 网格 - 将子项附加到左侧和向上的绝对位置的最佳方法?
- discord - 如何在等待反应中使用服装表情符号?
- java - 使用 BufferedReader 读取大文件并为每一行返回一个字符串是否存在潜在的内存不足问题?
- python - 为什么当评论被点赞时,点赞按钮会变回点赞按钮