proper name for python * operator?

2018-12-31 15:55发布

What is the correct name for operator *, as in function(*args)? unpack, unzip, something else?

7条回答
明月照影归
2楼-- · 2018-12-31 16:14

I believe it's most commonly called the "splat operator." Unpacking arguments is what it does.

查看更多
爱死公子算了
3楼-- · 2018-12-31 16:16

One can also call * a gather parameter (when used in function arguments definition) or a scatter operator (when used at function invocation).

As seen here: Think Python/Tuples/Variable-length argument tuples.

查看更多
美炸的是我
4楼-- · 2018-12-31 16:20

The Python Tutorial simply calls it 'the *-operator'. It performs unpacking of arbitrary argument lists.

查看更多
只若初见
5楼-- · 2018-12-31 16:22

I call *args "star args" or "varargs" and **kwargs "keyword args".

查看更多
皆成旧梦
6楼-- · 2018-12-31 16:23

I call it "positional expansion", as opposed to ** which I call "keyword expansion".

查看更多
爱死公子算了
7楼-- · 2018-12-31 16:29

In Ruby and Perl 6 this has been called "splat", and I think most people from those communities will figure out what you mean if you call it that.

The Python tutorial uses the phrase "unpacking argument lists", which is long and descriptive. I haven't heard any other particular name for it in Python.

查看更多
登录 后发表回答