-1

enter image description hereSo, I'm trying to call the function grocery_shopping- which accepts as arguments-greeting, an iterable (emp_name) and a dictionary (items). I'm passing arguments by keywords. However the output seems slightly weird since the argument passed as emp_name is being read as items! Can anyone help me in deciphering this (seemingly odd) behavior?

Pushp Sra
  • 606
  • 1
  • 6
  • 6
  • 1
    please provide text code and output instead of a screenshot of what it does – Axiumin_ Aug 17 '19 at 04:06
  • 1
    Why do you have `*` and `**` on the declarations of the `emp_name` and `items` parameters? – user2357112 Aug 17 '19 at 04:07
  • Possible duplicate of [What does \*\* (double star/asterisk) and \* (star/asterisk) do for parameters?](https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters) – Nathan Aug 17 '19 at 19:53

2 Answers2

2

When you define a function with a parameter like *args in python, it collects all the unnamed, non key-worded variables into a list named args. When you define a function with a parameter like **kwargs in python, it collects all of your key-worded variables into a dictionary named kwargs, where the key is the variable name and the value is the value. So what you've done is put 17.08.2019 into the greeting parameter, put nothing into emp_names, and put the key-worded arguments into items. Your first for loop will do nothing because emp_names is empty. In your second for loop, you print the dictionary items twice.

Google *args and **kwargs in python if you're still confused.

Jacob Rodal
  • 620
  • 1
  • 6
  • 12
2

You're passing emp_name and items as named args, therefore they both get included in **items. *emp_name is empty.

You should read up on *args and **kwargs.

John Gordon
  • 29,573
  • 7
  • 33
  • 58