Is it possible for a python function to ignore unused kwargs

If I have a simple function:

def add(a, b, c):
    return a + b + c

Is it possible for me to do this so that if I put an unused kwarg, it is simply ignored?

kwargs = dict(a=1, b=2, c=3, d=4)
print add(**kwargs) #prints 6
+5
source share
1 answer

Of course. Just add **kwargsfunctions to the signature:

def add(a, b, c, **kwargs):
    return a + b + c

kwargs = dict(a=1, b=2, c=3, d=4)
print add(**kwargs) 
#prints 6
+13
source

All Articles