[BangPypers] function parameter query

Nitin Kumar nitin.nitp at gmail.com
Wed Jan 23 09:25:00 CET 2013

>>> def show(c, d=False, **kwargs):
print 'c',c
print 'd',d
print kwargs

>>> def test(c, **kwargs):
    if (kwargs is None):
        kwargs = {}
    kwargs['d'] = 4
    kwargs['e'] = 5
    show(c, **kwargs)

>>> test(1)
c 1
d 4
{'e': 5}

Can anyone explain me why d (2nd parameter of function show) is getting set
to 3, when I am not passing any value to it and kwargs contains d=3.

Why kwargs value is getting set to d argument. Is this the
expected behavior?

Nitin K

More information about the BangPypers mailing list