Python Notes and Examples

Unpacking

Writing def foo(*args) ... creates a function that accepts zero or more positional args, slurping them all into a list:

This effectively unpacks x, then re-packs it into the stuff param in the body of the function.

Writing def foo(**named) ... creates a function that accepts zero or more named args, and which then slurps them all into a dict:

This effectively unpacks d into keyword-args, then repacks it into a dict (the named param) in the body of the function.

* * *

This is all separate from the other type of unpacking (“extended iterable unpacking”):

There’s no **whatever (“named args”-style) syntax for this kind of unpacking.