-2
def func(**kwargs):
    print(kwargs)

Are these two function calls identical?

d = {'id':1, 'name':'qwerty', 'dtype':3}
func1(**d)
func1(id=1, name='qwerty', dtype=3)

As far I understand, with a formal parameter in the form **arg, it receives a dictionary, while the formal parameter as *arg yields the tuple.

What is actually happening behind **kwargs?

khelwood
  • 55,782
  • 14
  • 81
  • 108
Mark
  • 6,052
  • 8
  • 61
  • 129
  • 2
    Have a look at [What is the purpose and use of \*\*kwargs?](https://stackoverflow.com/questions/1769403/what-is-the-purpose-and-use-of-kwargs) – khelwood Dec 13 '19 at 19:46
  • 1
    @khelwood, thanks for link. It explains everything I wanted to know about kwargs. – Mark Dec 13 '19 at 19:57

1 Answers1

0

It does exactly as you said.

**kwargs allows you to pass keyworded variable length of arguments to a function.

You should use **kwargs if you want to handle named arguments in a function.

** takes a dictionary and "spreads" it to a function as keyword (named) params.

gkpln3
  • 1,317
  • 10
  • 24