[Tutor] Might be a silly question!

Bill Mill bill.mill at gmail.com
Fri Feb 11 16:38:57 CET 2005


Jeff,

On Fri, 11 Feb 2005 10:03:30 -0500, Jeffrey Maitland <maitj at vianet.ca> wrote:
> 
> Hello all,
> 
> I am drawing a blank right now and can't seem to find anything on it and I
> am sure this issue has been addressed before, so here is the question.
> 
> Can and if you can how do you set a variable as a constant?
> 
> Example of what I mean: (this is loose and not python since variable type
> declaration is not needed in python)
> 
> CONST int gamma = 5
> 
> This would mean in my little mind that the variable gamma which is an
> integer of 5 can not be changed in the code and would throw an error if you
> tried. Just wondering if there is a way of doing this in Python.

There is no real way to guarantee this in Python.

>  This is
> just to clear this up in my mind it means nothing to my code since the way I
> write variable names any variable I want to remain unchanged I use caps to
> help distinguish easily.

Constants are enforced by convention in Python. Any variable with a
name in ALL CAPS is considered to be a constant, and it is considered
bad programming style to change it. While it sounds like a weak
system, and I'm sure there have been problems with it, I've never
heard of one. Remember to only import the names you need from the
classes you import, and you should be fine.

Peace
Bill Mill
bill.mill at gmail.com


More information about the Tutor mailing list