Search code examples
pythonparametersreferenceargumentspass-by-reference

can someone explain the python code to me, I don't understand


def all_aboard(a, *args, **kw):
    print(a, args, kw)

all_aboard(4, 7, 3, 0, x=10, y=64)

I want to know how this works as the output of the program is

4 (7, 3, 0) {'x': 10, 'y': 64}

How is the code computed?


Solution

  • all_aboard parameters are:

    1. a - you already know it
    2. *args - any number of parameters which are set as tuple
    3. **kw - give you all keyword arguments except for those corresponding to a formal parameter as a dictionary

    For this reason the output is:

    4 (7, 3, 0) {'x': 10, 'y': 64}
    

    since a = 4, *args = (7, 3, 0) and **kw = {'x': 10, 'y': 64}