Skip to content

Commit 29c6650

Browse files
暮晨ducheng
暮晨
authored and
ducheng
committed
EX.Needle in a Haystack
1 parent 0ef7690 commit 29c6650

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
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-)
@@ -1844,7 +1844,7 @@ class SomeClass:
18441844
18451845
---
18461846
1847-
### > Needle in a Haystack
1847+
### > Needle in a Haystack/大海捞针
18481848
18491849
1\.
18501850
```py
@@ -1853,11 +1853,11 @@ x, y = (0, 1) if True else None, None
18531853
18541854
**Output:**
18551855
```
1856-
>>> x, y # expected (0, 1)
1856+
>>> x, y # 期望的结果是 (0, 1)
18571857
((0, 1), None)
18581858
```
18591859
1860-
Almost every Python programmer has faced a similar situation.
1860+
几乎每个 Python 程序员都遇到过类似的情况.
18611861
18621862
2\.
18631863
```py
@@ -1883,10 +1883,10 @@ e
18831883
tuple()
18841884
```
18851885
1886-
#### 💡 Explanation:
1887-
* For 1, the correct statement for expected behavior is `x, y = (0, 1) if True else (None, None)`.
1888-
* 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.
1889-
* `()` is a special token and denotes empty `tuple`.
1886+
#### 💡 说明:
1887+
* 对于 1, 正确的语句是 `x, y = (0, 1) if True else (None, None)`.
1888+
* 对于 2, 正确的语句是 `t = ('one',)` 或者 `t = 'one',` (缺少逗号) 否则解释器会认为 `t` 是一个字符串, 并逐个字符对其进行迭代.
1889+
* `()` 是一个特殊的标记,表示空元组.
18901890
18911891
---
18921892

0 commit comments

Comments
 (0)