Re: What does it mean for Python to have “constants”?
Dennis Lee Bieber 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 "", line 1 > SyntaxError: can't assign to keyword > >>> False = object() > File "", line 1 > SyntaxError: can't assign to keyword > >>> None = object() > File "", 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. > This is true for Python 3, but the OP wrote his program in Python 2. In Python 2, you can do this (unfortunately): >>> True, False = False, True >>> if False: ... print("DOH!") ... DOH! -- https://mail.python.org/mailman/listinfo/python-list
What does it mean for Python to have “constants”? (was: variable scope of class objects)
Dennis Lee Bieber 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 "", line 1 SyntaxError: can't assign to keyword >>> False = object() File "", line 1 SyntaxError: can't assign to keyword >>> None = object() File "", 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 -- https://mail.python.org/mailman/listinfo/python-list