Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading