mirror of
https://github.com/satwikkansal/wtfpython
synced 2024-11-22 11:04:25 +01:00
Update link and add parenthesis to chained operators section
This commit is contained in:
parent
e9a49a5527
commit
d3a25fa14e
6
README.md
vendored
6
README.md
vendored
@ -384,15 +384,15 @@ False
|
|||||||
|
|
||||||
#### 💡 Explanation:
|
#### 💡 Explanation:
|
||||||
|
|
||||||
As per https://docs.python.org/3/reference/expressions.html#membership-test-operations
|
As per https://docs.python.org/3/reference/expressions.html#comparisons
|
||||||
|
|
||||||
> Formally, if a, b, c, ..., y, z are expressions and op1, op2, ..., opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once.
|
> Formally, if a, b, c, ..., y, z are expressions and op1, op2, ..., opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once.
|
||||||
|
|
||||||
While such behavior might seem silly to you in the above examples, it's fantastic with stuff like `a == b == c` and `0 <= x <= 100`.
|
While such behavior might seem silly to you in the above examples, it's fantastic with stuff like `a == b == c` and `0 <= x <= 100`.
|
||||||
|
|
||||||
* `False is False is False` is equivalent to `(False is False) and (False is False)`
|
* `False is False is False` is equivalent to `(False is False) and (False is False)`
|
||||||
* `True is False == False` is equivalent to `True is False and False == False` and since the first part of the statement (`True is False`) evaluates to `False`, the overall expression evaluates to `False`.
|
* `True is False == False` is equivalent to `(True is False) and (False == False)` and since the first part of the statement (`True is False`) evaluates to `False`, the overall expression evaluates to `False`.
|
||||||
* `1 > 0 < 1` is equivalent to `1 > 0 and 0 < 1` which evaluates to `True`.
|
* `1 > 0 < 1` is equivalent to `(1 > 0) and (0 < 1)` which evaluates to `True`.
|
||||||
* The expression `(1 > 0) < 1` is equivalent to `True < 1` and
|
* The expression `(1 > 0) < 1` is equivalent to `True < 1` and
|
||||||
```py
|
```py
|
||||||
>>> int(True)
|
>>> int(True)
|
||||||
|
Loading…
Reference in New Issue
Block a user