这是通过关键字参数解包来完成的,其中"字典可以提供关键字参数":
sample1(**argument_dictionary)
演示:
>>> def sample1(arg0=0, arg1=0, arg2=0, arg3=0, arg4=0): ... print(locals()) ... >>> argument_dictionary = {'arg0': 1, 'arg4': 4} >>> sample1(**argument_dictionary) {'arg0': 1, 'arg1': 0, 'arg2': 0, 'arg3': 0, 'arg4': 4}