Skip to content

Commit 3f6f413

Browse files
暮晨leisurelicht
暮晨
authored andcommitted
EX.The out of scope variable
1 parent 262035c commit 3f6f413

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ So, here we go...
6363
- [> Catching the Exceptions/捕获异常](#-catching-the-exceptions捕获异常)
6464
- [> Same operands, different story!/同人不同命!](#-same-operands-different-story同人不同命)
6565
- [> The out of scope variable/外部作用域变量](#-the-out-of-scope-variable外部作用域变量)
66-
- [> Be careful with chained operations](#-be-careful-with-chained-operations)
66+
- [> Be careful with chained operations/小心链式操作](#-be-careful-with-chained-operations小心链式操作)
6767
- [> Name resolution ignoring class scope](#-name-resolution-ignoring-class-scope)
6868
- [> Needle in a Haystack](#-needle-in-a-haystack)
6969
- [Section: The Hidden treasures!](#section-the-hidden-treasures)
@@ -1761,14 +1761,14 @@ UnboundLocalError: local variable 'a' referenced before assignment
17611761
17621762
---
17631763
1764-
### > Be careful with chained operations
1764+
### > Be careful with chained operations/小心链式操作
17651765
17661766
```py
1767-
>>> (False == False) in [False] # makes sense
1767+
>>> (False == False) in [False] # 可以理解
17681768
False
1769-
>>> False == (False in [False]) # makes sense
1769+
>>> False == (False in [False]) # 可以理解
17701770
False
1771-
>>> False == False in [False] # now what?
1771+
>>> False == False in [False] # 为毛?
17721772
True
17731773
17741774
>>> True is False == False
@@ -1784,25 +1784,25 @@ False
17841784
False
17851785
```
17861786
1787-
#### 💡 Explanation:
1787+
#### 💡 说明:
17881788
1789-
As per https://docs.python.org/2/reference/expressions.html#not-in
1789+
根据 https://docs.python.org/2/reference/expressions.html#not-in
17901790
1791-
> 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.
1791+
> 形式上, 如果 a, b, c, ..., y, z 是表达式, 而 op1, op2, ..., opN 是比较运算符, 那么除了每个表达式最多只出现一次以外 a op1 b op2 c ... y opN z 就等于 a op1 b and b op2 c and ... y opN z.
17921792
1793-
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`.
1793+
虽然上面的例子似乎很愚蠢, 但是像 `a == b == c` `0 <= x <= 100` 就很棒了.
17941794
1795-
* `False is False is False` is equivalent to `(False is False) and (False is False)`
1796-
* `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`.
1797-
* `1 > 0 < 1` is equivalent to `1 > 0 and 0 < 1` which evaluates to `True`.
1798-
* The expression `(1 > 0) < 1` is equivalent to `True < 1` and
1795+
* `False is False is False` 相当于 `(False is False) and (False is False)`
1796+
* `True is False == False` 相当于 `True is False and False == False`, 由于语句的第一部分 (`True is False`) 等于 `False`, 因此整个表达式的结果为 `False`.
1797+
* `1 > 0 < 1` 相当于 `1 > 0 and 0 < 1`, 所以最终结果为 `True`.
1798+
* 表达式 `(1 > 0) < 1` 相当于 `True < 1`
17991799
```py
18001800
>>> int(True)
18011801
1
1802-
>>> True + 1 #not relevant for this example, but just for fun
1802+
>>> True + 1 # 与这个例子无关,只是好玩
18031803
2
18041804
```
1805-
So, `1 < 1` evaluates to `False`
1805+
所以, `1 < 1` 等于 `False`
18061806
18071807
---
18081808

0 commit comments

Comments
 (0)