python function kwargs 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: python *arg **kwargs

>>> def f(a, b, *args, **kwargs):
...     print(F'a = {a}')
...     print(F'b = {b}')
...     print(F'args = {args}')
...     print(F'kwargs = {kwargs}')
...

>>> f(1, 2, 'foo', 'bar', 'baz', 'qux', x=100, y=200, z=300)
a = 1
b = 2
args = ('foo', 'bar', 'baz', 'qux')
kwargs = {'x': 100, 'y': 200, 'z': 300}