list as paremeters...
Mel Wilson
mwilson at the-wire.com
Sun Aug 31 10:32:08 EDT 2003
In article <bislss$ckt13$1 at ID-67890.news.uni-berlin.de>,
"Ulrich Petri" <ulope at gmx.de> wrote:
>IIRC Default values are not created each time the function called but rather
>only the first time (am i correct here?). And since a list is mutable it
>"rememberes" the previous value.
Default values are created when the 'def' statement is
executed, for example:
def f1 (t, usual=[]):
usual.append (t)
print 'F1:', usual
for x in [1, 2, 3, 4, 5]:
def f2 (t, usual=[]):
usual.append (t)
print 'F2:', usual
f1 (x)
f2 (x)
Results in
F1: [1]
F2: [1]
F1: [1, 2]
F2: [2]
F1: [1, 2, 3]
F2: [3]
F1: [1, 2, 3, 4]
F2: [4]
F1: [1, 2, 3, 4, 5]
F2: [5]
Regards. Mel.
More information about the Python-list
mailing list