Where is the default parameter in Python function

后端 未结 5 1567
情深已故
情深已故 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 09:20

    It is stored in the func_defaults attribute of the function object.

    >>> foo.func_defaults
    ([],)
    >>> foo()
    ([3],)
    

提交回复
热议问题