为什么我可以指定True = False(Python 2.7.9)

dou*_*e_j 5 python

为什么我能够使用Python 2.7.9 将Python关键字指定True为等于Python关键字False

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
>>>
Run Code Online (Sandbox Code Playgroud)

但是当切换到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
>>>
Run Code Online (Sandbox Code Playgroud)

Jas*_*uit 9

在Python 2中构建了True和False,但在Python 3中它们是关键字 - 因此是错误消息.严格地说,你不是指定它们而是遮蔽它们 - 你不能用关键字来做.