Note 5.5.2.
This workspace is provided for your convenience. You can use this activecode window to try out anything you like.
x*5 >= 10 and y-6 <= 20
will be evaluated so as to first perform the arithmetic and then check the relationships. The and
will be done last. Many programmers might place parentheses around the two relational expressions, (x*5 >= 10) and (y-6 <= 20)
. It is not necessary to do so, but causes no harm and may make it easier for people to read and understand the code.http://docs.python.org/py3k/reference/expressions.html#expression-lists
Level | Category | Operators |
---|---|---|
7(high) | exponent | ** |
6 | multiplication | *,/,//,% |
5 | addition | +,- |
4 | relational | ==,!=,<=,>=,>,< |
3 | logical | not |
2 | logical | and |
1(low) | logical | or |
'x' in y or z
in
operator is only on the left side of the or statement. It doesn’t get implemented on both sides of the or statement. In order to properly check that x is inside of either variable, the in operator must be used on both sides which looks like this:'x' in y or 'x' in z