Why is 'None' not assignable but 'True'/'False' are?

Alex Martelli aleax at mail.comcast.net
Mon Jan 2 14:23:55 EST 2006


Rodney Maxwell <rodney.maxwell at gmail.com> wrote:

> In Python 2.4.1:
> 
> >>> None = 99
> SyntaxError: assignment to None
> >>> True = 99
> >>> False = 99
> >>> True == False
> True
> -----------------------
> So why is 'None' special?

A legacy/backwards compatibility issue: None has been there 'forever',
so that no sensible code ever had any business assigning to it; but
'False' and 'True' were introduced just a few years ago, and it was
important to not break sensible existing code doing something like

True = 1
False = 0

at the very start.  In Python 3.0, when backwards compatibilities can be
introduced, True and False will become keywords (as will None); see
<http://www.python.org/peps/pep-3000.html>.


Alex



More information about the Python-list mailing list