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

tsaar2003 at yahoo.com tsaar2003 at yahoo.com
Wed May 3 01:28:55 EDT 2006


Bruno Desthuilliers wrote:
> tsaar2003 at yahoo.com a écrit :
> > Hi Pythonians,
> >
> > To begin with I'd like to apologize that I am not very experienced
> > Python programmer so please forgive me if the following text does not
> > make any sense.
> >
> > I have been missing constants in Python language.
>
> Why so ?
>
> I guess you're talking about named (symbolic) constants ? If so, just
> follow the convention : a name in ALL_UPPERCASE is a constant (or at
> least will be treated as such by anyone not wanting to mess with your
> package's implementation). No need to add extra syntax here IMHO.

Hi Bruno,

For example:

>>> A = []  # let's declare a "constant" here
>>> b = A   # and let's assign the constant here
>>> b.append('1') # OOPS!
>>> c = A
>>> print A
['1']
>>> print b
['1']
>>> print c
['1']

As you can see, the "constant" A can be modified this easily. But if
there were an intuitive mechanism to declare a symbol to be immutable,
then there won't be this problem.

Br,

- T.S.




More information about the Python-list mailing list