Re: [問題] function 選擇性使用 default kwarg

作者: lycantrope (阿寬)   2020-12-04 19:19:41
也可以用functools的partial先把b跟kwargs丟進去
from functools import partial
def f(a, b = 10):
print(a + b)
use_default_b = True
a = 5
params = {}
if use_default_b:
f(a, **params)
else:
partial(f, b = 100, **params)(a)

Links booklink

Contact Us: admin [ a t ] ucptt.com