Pythonic solution for conditional arguments passing

后端 未结 9 827
无人共我
无人共我 2020-12-29 20:24

I have a function with two optional parameters:

def func(a=0, b=10):
    return a+b

Somewhere else in my code I am doing some conditional a

9条回答
  •  误落风尘
    2020-12-29 21:03

    This might work:

    def f(**kwargs):
        a = get(kwargs, 0)
        b = get(kwargs, 10)
        return a + b
    

提交回复
热议问题