What is a function parameter =[] for?

Chris Angelico rosuav at gmail.com
Thu Nov 19 08:45:19 EST 2015


On Fri, Nov 20, 2015 at 12:19 AM, BartC <bc at freeuk.com> wrote:
> You presumably think differently because you have some inside knowledge of
> how Python works, and know that that [] undergoes a one-time assignment to a
> local, persistent 'default' variable where it's value can indeed by changed.
> (Thanks to another Python feature where an assignment is a very shallow copy
> of an object.) And it is that volatile variable that is the actual default.
>
> But not everyone is going to know that.

Correct: We think certain things because we understand how Python
behaves. You, too, can join the Inner Circle of Pythonistas; all you
have to do is read this (and/or watch the video):

http://nedbatchelder.com/text/names1.html

ChrisA



More information about the Python-list mailing list