In function-
Default value is *evaluated only once*.This makes different when the
default is a mutable object such as a list, dictionary or instance of most
classes.
I am not getting it properly-evaluated once?? different behaviour???--
please explain this.
On 2011/10/21 03:00 PM, Praveen Singh wrote:
In function-
Default value is *evaluated only once*.This makes different when the
default is a mutable object such as a list, dictionary or instance of
most classes.
I am not getting it properly-evaluated once?? different behaviour???--
please
Praveen Singh wrote:
In function-
Default value is *evaluated only once*.This makes different when the
default is a mutable object such as a list, dictionary or instance of most
classes.
I am not getting it properly-evaluated once?? different behaviour???--
please explain this.
Look at an
The same thing occurs when you use a mutable object like a list or a
dict. The default value is assigned once, and once only. But notice that
you can modify the default value, say by appending to it:
Not sure this will work exactly the same way in other IDEs, but in mine:
a = []
def
?
~~
From: Prasad, Ramit ramit.pra...@jpmorgan.com
To: tutor@python.org tutor@python.org
Sent: Friday, October 21, 2011 9:40 PM
Subject: Re: [Tutor] functions and default argument
The same thing occurs when you use a mutable object like a list or a
dict. The default value is assigned once
Interesting thread and webpages. Insightful, but is this really used as a
technique in daily practice? It feels a bit like a hack to me. Like the author
of one of the websites said: rule #1 don't mess with this.
I think the problem with rule #1 is that this can occur when you do *not*
On 21/10/11 21:40, Albert-Jan Roskam wrote:
Interesting thread and webpages. Insightful, but is this really used as
a technique in daily practice?
Yes, one example is where you use it for a counter to
determine how often a function gets called:
def reserveScarceResource(p1,p2,count = [0]):
Prasad, Ramit wrote:
Interesting thread and webpages. Insightful, but is this really
used as a technique in daily practice? It feels a bit like a hack
to me. Like the author of one of the websites said: rule #1 don't
mess with this.
I think the problem with rule #1 is that this can occur when