Basic Class/Instance Question
Maric Michaud
maric at aristote.info
Wed May 23 19:22:04 EDT 2007
Alan Franzoni a écrit :
> Il 23 May 2007 04:53:55 -0700, Siah ha scritto:
>
> [cut]
>
> No.
>
> It's because the *body* of the function gets evaluated every time the
> function is called, while the *definition* of the function gets evaluated
> just once, when the function is 'declared'.
>
> Your issue arises when the default value of the function (which is part of
> the definition, not of the body) is a mutable object, because it's the very
> same default value that gets modified at each time.
>
>
That is. Jython doesn't have the same rules about optimisation of common
literals :
maric at redflag2:~$ jython
Jython 2.1 on java1.4.2-03 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> () is ()
0
>>> 1 is 1
1
>>> def f(d=()) : return d
...
>>> f() is f()
1
More information about the Python-list
mailing list