Overriding True and False ?

Ben Finney ben+python at benfinney.id.au
Mon Jan 30 02:50:56 EST 2017

Irv Kalb <Irv at furrypants.com> writes:

> I teach intro to programming using Python. […]

Thank you for teaching Python to beginners!

> It seems very odd that Python allows you to override the values of
> True and False.

Yes, it is. That's why Python 3 forbids it::

    >>> True = "shadow"
      File "<stdin>", line 1
    SyntaxError: can't assign to keyword
    >>> False = "light"
      File "<stdin>", line 1
    SyntaxError: can't assign to keyword

When teaching Python, please do not teach Python 2. Your students should
learn Python 3 first, primarily, and for most of the course.

Python 2 is a legacy that will never gain new features, and will only
slip further behind the current supported Python version. That makes
Python 2 a poor choice for teaching to beginners.

 \          “The entertainment industry calls DRM "security" software, |
  `\         because it makes them secure from their customers.” —Cory |
_o__)                                             Doctorow, 2014-02-05 |
Ben Finney

More information about the Python-list mailing list