| Name | && (logical AND) |
||||
|---|---|---|---|---|---|
| Examples |
k = 0
for y in range(5, 95, 5):
k += 1
if y > 45 and k % 2 == 0:
# Set color to red for every other line
# for all y > 45.
stroke(color(255, 0, 0))
else:
stroke(0) # Set color to black
line(30, y, 80, y)
| ||||
| Description |
Compares two expressions and evaluates to True only if both evaluate to True. Returns False if one or both evaluate to False. The following list shows all possible combinations: True and False # Evaluates False because the second is False False and True # Evaluates False because the first is False True and True # Evaluates True because both are True False and False # Evaluates False because both are False The "and" operator is short-circuiting; it will not bother to evaluate its second expression of the first is False. That means, in the following example, that DoSomething is never called:
def DoSomething():
print "I did something!"
return True
x = False
if x and DoSomething():
print "This cannot happen."
|
||||
| Syntax | expression1 and expression2 | ||||
| Parameters |
| ||||
| Related |
or (logical OR) not (logical NOT) if |
Updated on Tue Feb 27 14:07:12 2024.
If you see any errors or have comments, please let us know.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License