What's the difference between True and False in python grammar?
<p>I'm reading <a href="https://docs.python.org/3/reference/grammar.html" rel="nofollow">the python language specification</a> and found there's a <code>None</code>,
<code>True</code>, and <code>False</code> token. I can understand the difference between <code>None</code> and
<code>False</code> since <code>None</code> is not a boolan. But, about <code>True</code> and <code>False</code>, why not
just <code>BOOLEAN</code> there? Is there any case where <code>True</code> and <code>False</code>
behave differently? Or is there any semantical difference?</p>

<p>Note that I'm asking about the difference in grammar not the boolean value which
is obviously different.</p>

<p>Presumably from the reference to which you linked you are referring to the grammatical production</p>

<pre><code>atom: ('(' [yield_expr|testlist_comp] ')' |
       '[' [testlist_comp] ']' |
       '{' [dictorsetmaker] '}' |
       NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
</code></pre>

<p>This simply gives the strings <code>None</code>, <code>True</code>, and <code>False</code> the same status as certain other language elements. While it would have been possible to create a definition of a Boolean atom which could either be <code>True</code> or <code>False</code> and use that in the grammar, what purpose would that have served?</p>

<p>In point of fact, even in 2.7 you can try to delete the <code>True</code> and <code>False</code> definitions from the <code>__builtins__</code> namespace:</p>

<pre><code>&gt;&gt;&gt; del __builtins__.True
&gt;&gt;&gt; del __builtins__.False

Traceback (most recent call last):
  File "/Users/sholden/.virtualenvs/jlab/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
NameError: global name 'True' is not defined
</code></pre>

<p>Interestingly, if you delete <code>False</code> first there is no complaint about the deletion of <code>True</code> :-)</p>

<p>However, this makes even quite standard Python make no sense at all:</p>

<pre><code>&gt;&gt;&gt; 1 == 1

Traceback (most recent call last):
  File "/Users/sholden/.virtualenvs/jlab/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
NameError: global name 'True' is not defined
</code></pre>

<p>This underlines that Python was produced as "a programming language for consenting adults." Ultimately it gives you enough rope to hang yourself if you are determined to do that.</p>

python