[docs] http://docs.python.org/tutorial/controlflow.html#default-argument-values

Bassam Gemayel gemayel at gmail.com
Sun Oct 14 20:46:35 CEST 2012


Hi guys,

A paragraph in <subject> states:
*
*
*If you don’t want the default to be shared between subsequent calls, you
can write the function like this instead:*
*
def f(a, L=None):
    if L is None:
        L = []
    L.append(a)
    return L
*
The above test *if L is None: *does not change the desired behaviour. i.e.
the accumulation of arguments.

Hence, it could induce the learner into the wrong conclusion.

May be you could add a comment regarding this or just write the function
like this:

def f(a, L=None): *#L could be set to any other immutable object, like 1*
    L = [] *#this will be stored in the local symbol table*
    L.append(a)
    return L
*
*
If the above is incorrect, please let me know why.

Thank you for a great tutorial and keep up the good work,

Bassam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20121014/f73bfa19/attachment-0001.html>


More information about the docs mailing list