Faqts : Computers : Programming : Languages : Python : Language and Syntax

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 4 people (50%) answered Yes
Recently 1 of 2 people (50%) answered Yes

Entry

Is it possible to create constant integers, floats etc?

Jul 18th, 2002 14:34
Michael Chermside, unknown unknown, David Goodger


The PREFERRED solution is to name the variable in all upper case, like this:
>>> CHARS_PER_LINE = 38
No, it doesn't make the variable read-only, but it DOES give a very
clear indication to the programmer that this is intended as a constant
and isn't meant to be changed. Python is a language which isn't really
designed for situations where your fellow programmers are attempting to
sabotage your code. If you DO find yourself in such a situation, we
recommend that you start looking for a new job.
However, if you REALLY, REALLY want a read-only constant, then there are
ways it can be done. See
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65207).