"Steven D'Aprano" <steve+comp.lang.pyt...@pearwood.info> wrote in message
news:4d743f70$0$29984$c3e8da3$54964...@news.astraweb.com...
On Sun, 06 Mar 2011 12:59:55 -0800, Westley Martínez wrote:

I'm confused. Can someone tell me if we're talking about constant as in
'fixed in memory' or as in 'you can't reassign' or both?

Python already has fixed in memory constants. They are immutable objects
like strings, ints, floats, etc. Once you create a string "spam", you
cannot modify it. This has been true about Python forever.

What Python doesn't have is constant *names*. Once you bind an object to
a name, like this:

s = "spam"

you can't modify the *object*, but you can rebind the name:

s = "Nobody expects the Spanish Inquisition!"

and now your code that expects s to be "spam" will fail. So the only new
feature under discussion is a way to bind-once names, which many people
call constants.

Another example:

pi=3.141592654

print ("pi is:",pi)

pi=42

print ("pi is now:",pi)

which is clearly undesirable.

Many languages just don't 'get' constants; C is one (the closest it comes is
'#define' and 'enum', while what it calls 'const' is really 'read-only
variable'), and perhaps Python is another.

But then, the dividing line between constants and 'variables' can get confused when the values involved are complex (strings and such), so might be understandable up to a point.


--
bartc
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to