Skip to content

Commit fedec82

Browse files
暮晨leisurelicht
暮晨
authored andcommitted
EX.Needle in a Haystack
1 parent 38b2bf6 commit fedec82

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ So, here we go...
6565
- [> The out of scope variable/外部作用域变量](#-the-out-of-scope-variable外部作用域变量)
6666
- [> Be careful with chained operations/小心链式操作](#-be-careful-with-chained-operations小心链式操作)
6767
- [> Name resolution ignoring class scope/忽略类作用域的名称解析](#-name-resolution-ignoring-class-scope忽略类作用域的名称解析)
68-
- [> Needle in a Haystack](#-needle-in-a-haystack)
68+
- [> Needle in a Haystack/大海捞针](#-needle-in-a-haystack大海捞针)
6969
- [Section: The Hidden treasures!](#section-the-hidden-treasures)
7070
- [> Okay Python, Can you make me fly? *](#-okay-python-can-you-make-me-fly-)
7171
- [> `goto`, but why? *](#-goto-but-why-)
@@ -1849,7 +1849,7 @@ class SomeClass:
18491849
18501850
---
18511851
1852-
### > Needle in a Haystack
1852+
### > Needle in a Haystack/大海捞针
18531853
18541854
1\.
18551855
```py
@@ -1858,11 +1858,11 @@ x, y = (0, 1) if True else None, None
18581858
18591859
**Output:**
18601860
```
1861-
>>> x, y # expected (0, 1)
1861+
>>> x, y # 期望的结果是 (0, 1)
18621862
((0, 1), None)
18631863
```
18641864
1865-
Almost every Python programmer has faced a similar situation.
1865+
几乎每个 Python 程序员都遇到过类似的情况.
18661866
18671867
2\.
18681868
```py
@@ -1888,10 +1888,10 @@ e
18881888
tuple()
18891889
```
18901890
1891-
#### 💡 Explanation:
1892-
* For 1, the correct statement for expected behavior is `x, y = (0, 1) if True else (None, None)`.
1893-
* For 2, the correct statement for expected behavior is `t = ('one',)` or `t = 'one',` (missing comma) otherwise the interpreter considers `t` to be a `str` and iterates over it character by character.
1894-
* `()` is a special token and denotes empty `tuple`.
1891+
#### 💡 说明:
1892+
* 对于 1, 正确的语句是 `x, y = (0, 1) if True else (None, None)`.
1893+
* 对于 2, 正确的语句是 `t = ('one',)` 或者 `t = 'one',` (缺少逗号) 否则解释器会认为 `t` 是一个字符串, 并逐个字符对其进行迭代.
1894+
* `()` 是一个特殊的标记,表示空元组.
18951895
18961896
---
18971897

0 commit comments

Comments
 (0)