Skip to content

Commit af423bc

Browse files
暮晨leisurelicht
暮晨
authored andcommitted
EX.Well, something is fishy
1 parent 75c8389 commit af423bc

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ So, here we go...
5353
- [Section: Appearances are deceptive!](#section-appearances-are-deceptive)
5454
- [> Skipping lines?/跳过一行?](#-skipping-lines跳过一行)
5555
- [> Teleportation/空间移动 *](#-teleportation空间移动-)
56-
- [> Well, something is fishy...](#-well-something-is-fishy)
56+
- [> Well, something is fishy.../嗯, 有些可疑...](#-well-something-is-fishy嗯有些可疑)
5757
- [Section: Watch out for the landmines!](#section-watch-out-for-the-landmines)
5858
- [> Modifying a dictionary while iterating over it](#-modifying-a-dictionary-while-iterating-over-it)
5959
- [> Stubborn `del` operator *](#-stubborn-del-operator-)
@@ -1302,12 +1302,12 @@ def energy_receive():
13021302
13031303
---
13041304
1305-
### > Well, something is fishy...
1305+
### > Well, something is fishy.../嗯,有些可疑...
13061306
13071307
```py
13081308
def square(x):
13091309
"""
1310-
A simple function to calculate the square of a number by addition.
1310+
一个通过加法计算平方的简单函数.
13111311
"""
13121312
sum_so_far = 0
13131313
for counter in range(x):
@@ -1322,17 +1322,17 @@ def square(x):
13221322
10
13231323
```
13241324
1325-
Shouldn't that be 100?
1325+
难道不应该是100吗?
13261326
1327-
**Note:** If you're not able to reproduce this, try running the file [mixed_tabs_and_spaces.py](/mixed_tabs_and_spaces.py) via the shell.
1327+
**注意:** 如果你无法重现, 可以尝试运行这个文件[mixed_tabs_and_spaces.py](/mixed_tabs_and_spaces.py).
13281328
1329-
#### 💡 Explanation
1329+
#### 💡 说明:
13301330
1331-
* **Don't mix tabs and spaces!** The character just preceding return is a "tab", and the code is indented by multiple of "4 spaces" elsewhere in the example.
1332-
* This is how Python handles tabs:
1333-
> First, tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight <...>
1334-
* So the "tab" at the last line of `square` function is replaced with eight spaces, and it gets into the loop.
1335-
* Python 3 is kind enough to throw an error for such cases automatically.
1331+
* **不要混用制表符(tab)和空格(space)!** 在上面的例子中, return 的前面是"1个制表符", 而其他部分的代码前面是 "4个空格".
1332+
* Python是这么处理制表符的:
1333+
> 首先, 制表符会从左到右依次被替换成8个空格, 直到被替换后的字符总数是八的倍数 <...>
1334+
* 因此, `square` 函数最后一行的制表符会被替换成8个空格, 导致return语句进入循环语句里面.
1335+
* Python 3 很友好, 在这种情况下会自动抛出错误.
13361336
13371337
**Output (Python 3.x):**
13381338
```py

mixed_tabs_and_spaces.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def square(x):
2+
sum_so_far = 0
3+
for _ in range(x):
4+
sum_so_far += x
5+
return sum_so_far # noqa: E999 # pylint: disable=mixed-indentation Python 3 will raise a TabError here
6+
7+
print(square(10))

0 commit comments

Comments
 (0)