User Guide
Table Of Contents
139
You can combine two (or more) expressions by surrounding each
with parenthesis and then using one of the logical operators
below.
For example:
if (variable1 == value) or (variable2 == value):
doThis()
You can use not() to reverse the result of an expression, turning
True to False and False to True. For example:
if not(variable == value):
doThis()
By using correct spacing, you can also put if statements inside
the code that runs if an earlier if statement is True. However,
using elif is often a little easier to read.
The example below runs doThis1() if the value of variable is 1. If
it is not, it checks whether the value is 2 and runs doThis2(). If it
is not 2 either, it checks whether the value is 3 and runs doThis3().
If the value is not 1, 2, or 3 then it runs doThisInAllOtherCases().
if variable == 1:
doThis1()
elif variable == 2:
>= Returns True if the first number is greater than or
equal to the second, and False if it is not.
<= Returns True if the first number is less than or
equal to the second, and False if it is not.
Operator Description
and Returns True if both expressions are True, and
False if either one is False.
or Returns True if either of the expressions is True.
Returns False if they are both False.
Operator Description