Why can I assign True = False (Python 2.7.9)

Why can I set the Python True keyword to equal the Python False keyword using Python 2.7.9?

 Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin >>> True True >>> True = False >>> True False >>> 

But when switching to Python 3.4.3:

 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin >>> True = False File "<stdin>", line 1 SyntaxError: can't assign to keyword >>> 
+5
source share
3 answers

True and False were built in Python 2, but in Python 3 they are keywords - thus an error message. Strictly speaking, you do not assign them, but obscure them — which you cannot do with the keyword.

+9
source

In python 3.x, True and False are reserved words

+2
source

Because in Python 3.X this is a keyword, and in 2.7.X it is a variable (how True=4869 works too, and also False=[4,8,6,9] )

+2
source

All Articles