243

运算符的正确名称是什么*,如function(*args)?解压,解压,还有别的吗?

4

9 回答 9

209

在 Ruby 和 Perl 6 中,这被称为“splat”,我想这些社区的大多数人都会明白如果你这么称呼它是什么意思。

Python 教程使用短语“解包参数列表”,它很长且具有描述性。

它也称为可迭代解包,或者在字典解包**的情况下 。

于 2010-02-23T22:53:19.657 回答
124

我称之为“位置扩展”,而不是**我称之为“关键字扩展”。

于 2010-02-24T02:40:50.563 回答
53

Python 教程简单地将其称为“ -operator *”。它执行任意参数列表的解包。

于 2010-02-23T22:57:18.993 回答
17

我说“star-args”,Python 人似乎明白我的意思。

**更棘手 - 我认为只是“qargs”,因为它通常用作**kw**kwargs

于 2010-02-23T23:10:06.043 回答
14

还可以调用*聚集参数(在函数参数定义中使用时)或分散运算符(在函数调用时使用时)。

如此处所示:想想 Python/Tuples/Variable-length argument tuples

于 2011-07-15T12:53:48.913 回答
8

我相信它最常被称为“splat 运算符”。解包参数就是它的作用。

于 2010-02-23T22:55:23.643 回答
2

对此的技术术语是可变参数函数。所以从某种意义上说,这是正确的术语,与编程语言无关。

That said, in different languages the term does have legitimate names. As others have mentioned, it is called "splat" in ruby, julia, and several other languages and is noted by that name in official documentation. In javascript it is called the "spread" syntax. It has many other names in many other languages, as mentioned in other answers. Whatever you call it, it's quite useful!

于 2021-06-02T23:04:02.047 回答
0

我将 *args 称为“star args”或“varargs”,将 **kwargs 称为“keyword args”。

于 2011-05-09T21:22:31.617 回答
0

对于一个俗名,有“splatting”。

对于参数(列表类型),您使用 single *,对于关键字参数(字典类型),您使用 double **

两者***有时也被称为“飞溅”。

请参阅正在使用的此名称的参考: https ://stackoverflow.com/a/47875892/14305096

于 2020-10-13T11:40:19.280 回答