1

I suppose I understand how to use them individually in functions like ...

f(*args) or f(**kargs)

But what if a function accepts both as arguments? Ex: f(*args, **kargs)

FlyingBumble
  • 195
  • 1
  • 11

2 Answers2

1

Yes, it works

def f(*args, **kwargs):
    pass

If you call function like this f(1, 3, "foo", [1, 2, 10], a=1, apple=33), then in function args will be (1, 3, "foo", [1, 2, 10]), kwargs will be{'a': 1, 'apple': 33}.

It will work too

def f(a, b, foo, *args, **kwargs):
    pass

But if we call this function with the same arguments, a will be 1, b will be 3, foo will be "foo", args will be ([1, 2, 10]), kwargs will be the same.

f43d65
  • 2,264
  • 11
  • 15
1

*args gets positional arguments; **kwargs gets named arguments. For instance:

f(1, 2, 3, a=1, b=2, c=3)

would pass

args = (1, 2, 3)
kwargs = {a: 1, b: 2, c: 3}