Possible constant assignment operators ":=" and "::=" for Python

Christophe chris.cavalaria at free.fr
Thu May 4 10:55:39 CEST 2006


Fredrik Lundh a écrit :
> Christophe wrote:
> 
> 
>>That's easy, since A is a symbolic constant know at compile time, and
>>since it's a known mutable objet, the code once compiled will be
>>equivalent to:
>>
>> >>> b = [[]]
>>
>> >>> # much later
>> >>> b|0].append('1')
> 
> 
> the OP talked about constants as names for immutable objects, not pre-
> processor macros.  but alright, using the "symbolic constant" approach,
> what would this print ?
> 
>     >>> def foo(var):
>     ...     var.append('1')
>     ...     print var
>     ...
>     >>> b = []
>     >>> foo(b)
>     >>> foo(b)

I think you've made a mistake in your example. This is valid today's 
Python you know :) And it'll print more or less :
['1']
['1', '1']

> and this ?
> 
>     >>> constant A = []
>     >>> print A is A

Obviously, False.



More information about the Python-list mailing list