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