What does it mean for Python to have “constants”? (was: variable scope of class objects)

Ben Finney ben+python at benfinney.id.au
Tue Oct 20 20:27:51 EDT 2015


Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:

> (Python does not have anything that one might consider a true constant
> -- other than the language defined singletons: None, and maybe by now
> True and False).

Python now deals with those by making the names keywords::

    >>> True = object()
      File "<stdin>", line 1
    SyntaxError: can't assign to keyword
    >>> False = object()
      File "<stdin>", line 1
    SyntaxError: can't assign to keyword
    >>> None = object()
      File "<stdin>", line 1
    SyntaxError: can't assign to keyword

which seems to rather avoid the question of whether they are “constants”
as would be understood by newcomers experienced with that term in other
languages.

-- 
 \       “Crime is contagious… if the government becomes a lawbreaker, |
  `\          it breeds contempt for the law.” —Justice Louis Brandeis |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list