268

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

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Anycorn
  • 50,217
  • 42
  • 167
  • 261
  • 16
    Javascript has the equivalent **spread** `...` operator. – Wolfgang Kuehn Dec 31 '16 at 14:04
  • Just for reference, in the C++, it is called Dereference Operator (ref: https://www.cplusplus.com/doc/tutorial/pointers/). Additionally, in Python, all variable to function (arguments) is pass by assignment. (ref: https://docs.python.org/3/faq/programming.html#how-do-i-write-a-function-with-output-parameters-call-by-reference) – Cloud Cho Mar 23 '21 at 04:17
  • @CloudCho The one in C++ stands for something entirely different. – Sнаđошƒаӽ Jun 06 '21 at 15:37
  • @Sнаđошƒаӽ Would you describe the difference between Dereference Operator (C++) and Unpacking Operator (Python)? I thought both of them related to memory location rather than value in memory. Thanks. – Cloud Cho Jun 09 '21 at 18:02
  • @CloudCho Take a look at the [official documentation](https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists). – Sнаđошƒаӽ Jun 10 '21 at 03:47
  • @Sнаđошƒаӽ, Thanks for the link. I see the first example with * is not related to memory, but the second example with ** and Dictionary data structure looks different. When I `print(*Dictionary)`, it shows only Key in Dictionary. Would you give additional information? Thanks. – Cloud Cho Jun 10 '21 at 17:33
  • @CloudCho, the C++ analogue of Python's `*` is also `...`, used in [template parameter packs](https://en.cppreference.com/w/cpp/language/parameter_pack). – Dumaiu Jul 11 '22 at 01:38

9 Answers9

234

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.

It is also referred to as iterable unpacking, or in the case of **, dictionary unpacking.

Zombo
  • 1
  • 62
  • 391
  • 407
ephemient
  • 198,619
  • 38
  • 280
  • 391
130

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

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
55

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

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
Danilo Piazzalunga
  • 7,590
  • 5
  • 49
  • 75
  • 1
    This is the most accurate answer and it's a shame it wasn't accepted! – Nir Alfasi Nov 21 '15 at 04:19
  • 6
    @alfasin: The expression 'the `*`-operator' is ambiguous since `*` – depending on the context – can perform either argument expansion or multiplication which are two different operations. – HelloGoodbye Feb 07 '17 at 13:53
  • 2
    @HelloGoodbye and it's really not difficult to understand which one it is from the context it's in. – Nir Alfasi Feb 07 '17 at 18:22
  • 3
    Seems like the OP was asking how to pronounciate (which may or may not be a word itself - that's another rabbit hole) `*`. By saying it's the `*-operator` is simply throwing the question back as an answer. OP probably wanted to know how to say it out loud (or in his head) when he encounters it. This is all new to me, and I'll be going with "splat!". – elPastor Mar 23 '19 at 19:09
  • If we go for simple let's call it star-operator. But ** could be dasterisk. Hm.. – TaW Jul 31 '23 at 10:03
17

I say "star-args" and Python people seem to know what i mean.

** is trickier - I think just "qargs" since it is usually used as **kw or **kwargs

John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • 2
    I also just say `kwargs`, although that doesn't really refer to the operator itself I suppose. – TM. Feb 23 '10 at 23:32
17

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.

Anton Strogonoff
  • 32,294
  • 8
  • 53
  • 61
10

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

Community
  • 1
  • 1
Chuck
  • 234,037
  • 30
  • 302
  • 389
3

For a colloquial name there is "splatting".

For arguments (list type) you use single * and for keyword arguments (dictionary type) you use double **.

Both * and ** is sometimes referred to as "splatting".

See for reference of this name being used: https://stackoverflow.com/a/47875892/14305096

Zaffer
  • 1,290
  • 13
  • 32
3

The technical term for this is a Variadic function. So in a sense, that's the correct term without regard to programming language.

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!

James Tomasino
  • 3,520
  • 1
  • 20
  • 38
-1

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

wberry
  • 18,519
  • 8
  • 53
  • 85