Where is the default parameter in Python function

后端 未结 5 1575
情深已故
情深已故 2021-01-05 08:52

I think many people have seen the python\'s function which receives default parameters. For example:

def foo(a=[]):
    a.append(3)
    return a
5条回答
  •  醉酒成梦
    2021-01-05 09:28

    It's in the function object, in the func_defaults:

    def f(a=[]): a.append(3)
    
    print f.func_defaults # ([],)
    
    f()
    
    print f.func_defaults # ([3],)
    

提交回复
热议问题