if, else, and elif Statements
Read this for more on conditional statements.
7. Order of evaluation
Precedence rules
The order in which operators are evaluated in an expression is known as precedence of operators.
operator | description | Example |
---|---|---|
() | parentheses are evaluated first | (2+5*3) - (5/6+2*4) |
** // % / * - + | arithmetic operations next (in order) | 10-2**5 >= 10%7 |
< <= > >= == != | then comparisons and membership operators | a > 9 and b in [1, 2, 3] |
not | negation operator next | not (a > 9) or b == 2 |
and | conjunction (and) next | a > 9 or a < 0 and b > 1 |
or | disjunction (or) last | a > 9 or a < 0 and b > 1 |
Example: Let's evaluate the Boolean expression below for:
- g = 12, b = True, and a = 17
- g >= 90 or b and a > 10
- (g >= 90) or (b and a > 100
- (g >= 90) or (b and a > 100)
- F or (T and F)
- F or F