Return value of an assignment statement?
John Henry
john106henry at hotmail.com
Sat Feb 23 13:13:05 EST 2008
On Feb 23, 2:59 am, Jeff Schwab <j... at schwabcenter.com> wrote:
> Dennis Lee Bieber wrote:
> > On Fri, 22 Feb 2008 11:23:27 -0800, Jeff Schwab <j... at schwabcenter.com>
> > declaimed the following in comp.lang.python:
>
> >> I'm about through with this discussion, but FWIW, this is a real gotcha
> >> for me and many others. This is a case where Python does not do what
> >> many programmers expect, and it at least takes some getting used-to.
>
> > As opposed to the twice monthly shocked newbie discovering that a
> > mutable as a function default doesn't reset on the next invocation?
>
> > In that aspect, it all comes down to the difference between mutables
> > and immutables in Python.
>
> You know what's illuminating the discussion? Everybody thinks they
> understand this issue, but the explanations are contradictory. It seems
> like half the folks think this is an issue of mutability vs.
> immutability, and the other half believe that has nothing to do with it.
You mean like this: :=)
def invoke_some_fct(parent):
y = parent.x
try:
y += [ 'world' ]
except:
y += ( 'world', )
print y, parent.x
class abc:
def __init__(self):
self.x=[ 'hello' ]
invoke_some_fct(self)
print self.x
self.x=( 'hello', )
invoke_some_fct(self)
print self.x
hw = abc()
More information about the Python-list
mailing list