On 7 May 2015 at 13:03, Emile van Sebille <[email protected]> wrote:
> Compare to:
>
> def testid(K=1000000):
> K += 10
> return 'the ID is', id(K), K
>
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. It
used lists so I tried ints. Although I realized persistence also works for
dicts ;')
def testid(newitem, K={}):
K[newitem] = newitem + 'item'
return 'the ID is', id(K), K
>>> testid('bonk')
('the ID is', 18263656, {'bonk': 'bonkitem'})
>>> testid('clonk')
('the ID is', 18263656, {'bonk': 'bonkitem', 'clonk': 'clonkitem'})
>>> testid('spam')
('the ID is', 18263656, {'bonk': 'bonkitem', 'clonk': 'clonkitem', 'spam':
'spamitem'})
--
Jim
"What a rotten, failed experiment. I'll start over. Maybe dogs instead of
monkeys this time." --God
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor