Constants and Globals

Peter Hansen peter at engcorp.com
Sun Dec 15 14:46:19 EST 2002


Mike Meyer wrote:
> 
> You appear to be suffering from a standard newbie confusion about
> variables. Variables aren't objects, they refer to them. Assignment
> causes the right hand variable to refer to the object created by the
> expression on the left hand side of the '='.  

I believe you mixed up "right" and "left" in the above.  The assignment
makes the thing on the *left* side refer to the object on the *right*
side.  Other than that, good explanation.

> So yes, there are constants. You can make variables refer to them. You
> can't tell the interpreter to disallow assignments to a variable. So
> there aren't constants the way you mean it.

A minor note: for those who *really* need this, there are ways
to do it using some of Python's more sophisticated features.  
A newbie doesn't need this though, and it's debatable (and often
debated :-) whether anyone does.

-Peter



More information about the Python-list mailing list