You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [> 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本质上我们都一样-)
32
32
- [> For what?](#-for-what)
33
33
- [> Evaluation time discrepancy](#-evaluation-time-discrepancy)
34
34
- [> `is` is not what it is!](#-is-is-not-what-it-is)
@@ -271,7 +271,7 @@ def some_func():
271
271
272
272
---
273
273
274
-
### > Deep down, we're all the same. *
274
+
### > Deep down, we're all the same./本质上,我们都一样. *
275
275
276
276
```py
277
277
classWTF:
@@ -280,22 +280,22 @@ class WTF:
280
280
281
281
**Output:**
282
282
```py
283
-
>>> WTF() == WTF() #two different instances can't be equal
283
+
>>> WTF() == WTF() #两个不同的对象应该不相等
284
284
False
285
-
>>> WTF() is WTF() #identities are also different
285
+
>>> WTF() is WTF() #也不相同
286
286
False
287
-
>>>hash(WTF()) ==hash(WTF()) #hashes _should_ be different as well
287
+
>>>hash(WTF()) ==hash(WTF()) #哈希值也应该不同
288
288
True
289
289
>>>id(WTF()) ==id(WTF())
290
290
True
291
291
```
292
292
293
-
#### 💡 Explanation:
293
+
#### 💡 说明:
294
294
295
-
*When`id`was called, Python created a `WTF`classobjectand passed it to the `id`function. The`id`function takes its `id` (its memory location), and throws away the object. The objectis destroyed.
296
-
*When we do this twice in succession, Python allocates the same memory location to this second objectas well. Since (in CPython) `id`uses the memory location as the objectid, 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.
0 commit comments