On 05/07/2015 05:25 PM, Alan Gauld wrote:
On 07/05/15 21:54, Jim Mooney Py3.4.3winXP wrote:

Ah, thanks. I forgot small integers are saved in a table. I was
looking at
a demo that pointers to defaults in function parameters are persistent.

But remember they variables are NOT pointers.
They are keys in a dictionary. Very different.

Also the id() function is implementation dependant so
although it may seem to be a memory address in CPython
it is something else in IronPython and something else
again in Jython. The only thing guaranteed is that
it is a unique id for that object.

Unique as long as the two objects you're examining exist at the same time. An id() may be reused once the first object is destroyed. And in general for CPython that happens a lot for small objects.


As to default parameter values, the default object is
persistent but if you reassign the parameter inside
the function it will obviously lose its binding to
the default object. It will only be reassigned to
it on the next function call (unless it's a generator
function).



--
DaveA
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to