**kwargs用法举例

def test_kwarges(out : bool = False, **kwargs):    
    a = kwargs.get("a", "test-a")    
    x = kwargs.get("x", "test-x")
    print(a, x)
    print(out)


kwargs = {"a":1, "b":2}
test_kwarges(**kwargs)
test_kwarges(out=True, x=1, y=2)

  要点:调用函数时, out 必须在kwargs的内容之前

posted on 2023-12-08 16:48  金凯旋  阅读(27)  评论(0编辑  收藏  举报

导航