Python Arguments __defaults__

There is an interesting example in the Python docs:

# Python 3.5
def f(a, L=[]):
    L.append(a)
    return L

print(f(1))
print(f(2))
print(f(3))
# [1, 2, 3]

You can see how the arguments get stored within defaults in the snippet below:

Python __defaults__

Comments

Let us know your comments by tweeting to @codeselfstudy or emailing [email protected].
(The commenting system here is offline for the moment but will return soon. This blog is still under construction.)

Return to the Code Self Study Blog.