Optional parameter object re-used when instantiating multiple objects
jeremiah.dodds at gmail.com
Thu Nov 20 03:13:19 CET 2008
On Wed, Nov 19, 2008 at 8:58 PM, alex23 <wuwei23 at gmail.com> wrote:
> On Nov 20, 10:14 am, Aaron Brady <castiro... at gmail.com> wrote:
> > If you had a menu in a browser interface that had the items, say,
> > 'Stop' and 'Reload', what would you expect to happen if you clicked on
> > them?
> If you had a keyword called 'def', which defined functions, would you
> expect it to define said functions when it executed, or on each
> function call?
I think that most of the issue here stems from people not understanding the
"quirks" of "variable assignment" in python, not so much expecting the def
statement to get re-evaluated every time a function is called.
I'm willing to bet that people surprised by the behavior of def are also
a = [1,2,3]
b = a
a = 4
b = a
b = 5
This makes sense if you've read (and understood!) the docs, or if you're
familiar with other programming languages that have similar behavior, but a
lot of people learn python as a first language these days - and a lot of
those people learn it largely by playing around, not by studying the
documentation. I can definitely see how the behavior could be confusing to a
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list