Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 14
    Sorry to bring this up 7 years later, but if you removed ** from the fn declaration to just have def foo(argd): and you ran foo(d) you would get the same result. Why then are ** used? Commented Oct 9, 2015 at 23:42
  • 6
    @David yes, you're right. The example is just to demonstrate how to "unpack" a dict and then "repack" it inside the function. For example, foo(a="b", c="d") would also provide the same output as foo(**d). Commented Dec 2, 2015 at 18:04
  • 3
    I saw the first answer and I was like , "Noo, this is not what I wanted", and then I saw your answer :) Commented Feb 7, 2017 at 10:06
  • 3
    For clarity, this example is using * for unpacking a sequence (such as a list) when passed as an argument to a function that uses *args for an arbitrary number of positional arguments. Commented Sep 26, 2020 at 18:55
  • @howtocode No, * is actually unpacking the arguments - no need for *args in the function definition. The same goes for **params. To others, to clarify, it unpacks both positional and named arguments from a list, respectively. So :david, your example only works because one argument is unpacked into one argument. Commented Dec 18, 2023 at 4:50