python kwargs what is code example
Example 1: args kwargs python
>>> def argsKwargs(*args, **kwargs):
... print(args)
... print(kwargs)
...
>>> argsKwargs('1', 1, 'slgotting.com', upvote='yes', is_true=True, test=1, sufficient_example=True)
('1', 1, 'slgotting.com')
{'upvote': 'yes', 'is_true': True, 'test': 1, 'sufficient_example': True}
Example 2: **kwargs
When it iterating over a dictionary you are only able to iterate over
the keys not the values. The ** when placed before a variable will allow
you to iterate and unpack both key and value pairs. Because you are
unpacking both key and value this will return the result as a dictionary.