On Tue, Mar 19, 2019 at 7:53 AM Wes Turner <wes.tur...@gmail.com> wrote:
>
> 'True' is a keyword. (Which is now immutable in Python 3.X?)
>
> >>> True = 1
>   File "<stdin>", line 1
> SyntaxError: can't assign to keyword

In Python 3, the source code token "True" is a keyword literal that
always represents the bool value True.

> In Python 2:
>
> >>> True
> True
> >>> True is True
> True
> >>> True = 1
> >>> True is 1
> True
> >>> True is None
> False
> >>> True = None
> >>> True is None
> True

In Python 2, the source code token "True" is simply a name, and there
is a built-in of that name. Before it became a built-in, it was common
for scripts to have their own definitions of True and False [1], so to
avoid unnecessary breakage, they were made assignable in the normal
way. Python 3 simplifies this by making them keywords.

But either way, the *values* True and False are special, and are the
only two instances of the bool type that will ever exist.

ChrisA

[1] Note that I learned about this in history class; it was before my time.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to