a = 2 |
|
|
We must define scope before the
print. In fact python relies on indentation (whitespace at the beginning of a line) to define scope in the code. |
if (a > b): |
|
|
The
elif keyword is used to say if the previous conditions were not true, then try this condition. |
if (a > b): |
|
|
The else keyword catches anything which isn't caught by the preceding conditions.
|
if a < b: print("a < b") |
|
Two conditions:
|
|
print("a > b") if a > b else print("a < b") |
|
|
Three conditions:
|
|
print("a > b") if a > b else print("a is equal to b") if a == b else print("a < b") |
if (condition_1 and condition_2): |
if (condition_1 or condition_2): |
if (a > 0): |
if (a < b): |
|
if statements cannot be empty, but if we for some reason have an if statement with no content, we can put in the pass statement to avoid getting an error. |
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.