Something in the function tutorial confused me.

Lee Fleming countblabula at yahoo.com
Mon Aug 6 19:17:22 CEST 2007


On Aug 6, 6:25 am, Neil Cerutti <horp... at yahoo.com> wrote:
Because when the function is called,  the line


>     if y is None: y = []


is executed, binding a brand new empty list to y. This
"rebinding" happens every time the function is called, unless you
provide an argument for y that is not None.

Thanks for the prompt replies. But I am still confused. This is what
confuses me....
The first time you call the function, say with f(23), after the
function ends,
y no longer equals None. Therefore, calling f again, this time like
this f(24),
should make y equal [23,24], because the 'if y == None' test fails, or
at least I think it
fails, because y.append(x) added something that was not equal to None
during the previous call.

Please help me!




More information about the Python-list mailing list