Possible constant assignment operators ":=" and "::=" for Python
Christophe
chris.cavalaria at free.fr
Tue May 9 05:31:42 EDT 2006
Fredrik Lundh a écrit :
> Christophe wrote:
>
>
>>I think you've made a mistake in your example.
>
>
> >>> constant A = []
> >>> def foo(var):
> ... var.append('1')
> ... print var
> ...
> >>> b = A
> >>> foo(b)
> >>> foo(b)
>
>
>>>and this ?
>>>
>>> >>> constant A = []
>>> >>> print A is A
>>
>>Obviously, False.
>
>
> why obviously ? why shouldn't a constant be constant ?
>
> </F>
Because the name A is bound by the compiler to mean construct a new
object since [] is mutable.
Same reason why :
>>> def A(): return []
>>> print A() is A()
False
It gives btw one possible implementation ;)
More information about the Python-list
mailing list