Game Development Reference
In-Depth Information
This is all done by the Python interpreter, but it is important to understand how the
interpreter does this. This picture shows the steps of how the interpreter evaluates the
condition (if the value of cave is the blank string):
while cave != '1' and cave != '2':
while '' != '1' and cave != '2':
while True and cave != '2':
while True and '' != '2':
while True and True:
while True:
Experimenting with the
and
and
or
Operators
Try typing the following into the interactive shell:
>>> True and True
True
>>> True and False
False
>>> False and True
False
>>> False and False
False
There are two other boolean operators. The next one is the
or
operator. The or operator
works similar to the and, except it will evaluate to
True
if
either
of the two boolean values
are
True
. The only time the
or
operator evaluates to
False
is if both of the boolean
values are
False
.
The sentence "Cats have whiskers or dogs have wings." is true. Even though dogs don't
have wings, when we say "or" we mean that one of the two parts is true. The sentence "Cats
have whiskers or dogs have tails." is also true. (Most of the time when we say "this OR
that", we mean one thing is true but the other thing is false. In programming, "or" means
that either of the things are true, or maybe both of the things are true.)