Skip to content

Commit 0e675fd

Browse files
author
暮晨
committed
EX.Deep down, we're all the same
1 parent 12c5c25 commit 0e675fd

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ So, here we go...
2828
- [> Strings can be tricky sometimes/微妙的字符串 *](#-strings-can-be-tricky-sometimes微妙的字符串-)
2929
- [> Time for some hash brownies!/是时候来点蛋糕了!](#-time-for-some-hash-brownies是时候来点蛋糕了)
3030
- [> Return return everywhere!/到处返回!](#-return-return-everywhere到处返回)
31-
- [> Deep down, we're all the same. *](#-deep-down-were-all-the-same-)
31+
- [> Deep down, we're all the same./本质上,我们都一样. *](#-deep-down-were-all-the-same本质上我们都一样-)
3232
- [> For what?](#-for-what)
3333
- [> Evaluation time discrepancy](#-evaluation-time-discrepancy)
3434
- [> `is` is not what it is!](#-is-is-not-what-it-is)
@@ -271,7 +271,7 @@ def some_func():
271271
272272
---
273273
274-
### > Deep down, we're all the same. *
274+
### > Deep down, we're all the same./本质上,我们都一样. *
275275
276276
```py
277277
class WTF:
@@ -280,22 +280,22 @@ class WTF:
280280
281281
**Output:**
282282
```py
283-
>>> WTF() == WTF() # two different instances can't be equal
283+
>>> WTF() == WTF() # 两个不同的对象应该不相等
284284
False
285-
>>> WTF() is WTF() # identities are also different
285+
>>> WTF() is WTF() # 也不相同
286286
False
287-
>>> hash(WTF()) == hash(WTF()) # hashes _should_ be different as well
287+
>>> hash(WTF()) == hash(WTF()) # 哈希值也应该不同
288288
True
289289
>>> id(WTF()) == id(WTF())
290290
True
291291
```
292292
293-
#### 💡 Explanation:
293+
#### 💡 说明:
294294
295-
* When `id` was called, Python created a `WTF` class object and passed it to the `id` function. The `id` function takes its `id` (its memory location), and throws away the object. The object is destroyed.
296-
* When we do this twice in succession, Python allocates the same memory location to this second object as well. Since (in CPython) `id` uses the memory location as the object id, the id of the two objects is the same.
297-
* So, object's id is unique only for the lifetime of the object. After the object is destroyed, or before it is created, something else can have the same id.
298-
* But why did the `is` operator evaluated to `False`? Let's see with this snippet.
295+
* 当调用 `id` 函数时, Python 创建了一个 `WTF` 类的对象并传给 `id` 函数. 然后 `id` 函数获取其id值 (也就是内存地址), 然后丢弃该对象. 该对象就被销毁了.
296+
* 当我们连续两次进行这个操作时, Python会将相同的内存地址分配给第二个对象. 因为 (在CPython中) `id` 函数使用对象的内存地址作为对象的id值, 所以两个对象的id值是相同的.
297+
* 综上, 对象的id值仅仅在对象的生命周期内唯一. 在对象被销毁之后, 或被创建之前, 其他对象可以具有相同的id.
298+
* 那为什么 `is` 操作的结果为 `False`? 让我们看看这段代码.
299299
```py
300300
class WTF(object):
301301
def __init__(self): print("I")
@@ -317,7 +317,7 @@ True
317317
D
318318
True
319319
```
320-
As you may observe, the order in which the objects are destroyed is what made all the difference here.
320+
正如你所看到的, 对象销毁的顺序是造成所有不同之处的原因.
321321
322322
---
323323

0 commit comments

Comments
 (0)