Questioning the effects of multiple assignment
DL Neil
PythonList at DancesWithMice.info
Wed Jul 8 18:37:33 EDT 2020
On 8/07/20 10:19 PM, Peter J. Holzer wrote:
> On 2020-07-08 12:26:06 +1200, dn via Python-list wrote:
> OTOH, using a tuple doesn't prevent the function from mutating mutable
> arguments:
>
> #!/usr/bin/python3
> def f(*a):
> a[0]["new"] = 2
>
> v = { "old": 1}
> f(v)
> print(v)
>
> prints «{'old': 1, 'new': 2}».
Very clever!
Place a mutable inside the immutable parameter...
Any advance on return new_mutable?
--
Regards =dn
More information about the Python-list
mailing list