Game Development Reference
In-Depth Information
6 - Dragon Realm
Try typing the following into the interactive shell:
>>> True or True
True
>>> True or False
True
>>> False or True
True
>>> False or False
False
Experimenting with the
not
Operator
The third boolean operator is
not
. The not operator is different from every other
operator we've seen before, because it only works on one value, not two. There is only
value on the right side of the
not
keyword, and none on the left. The not operator will
evaluate to
True
as
False
and will evaluate
False
as
True
.
Try typing the following into the interactive shell:
>>> not True
False
>>> not False
True
>>> True not
SyntaxError: invalid syntax (<pyshell#0>, line 1)
Notice that if we put the boolean value on the left side of the
not
operator results in a
syntax error.
We can use both the
and
and
not
operators in a single expression. Try typing
True
and
not False
into the shell:
>>> True and not False
True
Normally the expression
True and False
would evaluate to
False
. But the
True
and
not False
expression evaluates to
True
. This is because
not False
evaluates to
True
, which turns the expression into
True and True
, which evaluates to
True
.