Mas Bagol Mas Bagol - 2 months ago 13
Python Question

What's the difference between True and False in python grammar?

I'm reading the python language specification and found there's a

None
,
True
, and
False
token. I can understand the difference between
None
and
False
since
None
is not a boolan. But, about
True
and
False
, why not
just
BOOLEAN
there? Is there any case where
True
and
False

behave differently? Or is there any semantical difference?

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

wim wim
Answer

This is a formalization of the fact that True and False are special names in python3: you can't assign to them.

The reason that they aren't BOOLEAN is simply that boolean isn't a valid token for the parser.

Note: You will find this detail missing in the python2 grammar, where you can actually assign to the names True and False (...if you want to watch the world burn).