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本质上我们都一样-)
32
32
- [> For what?/为什么?](#-for-what为什么)
33
-
- [> Evaluation time discrepancy](#-evaluation-time-discrepancy)
33
+
- [> Evaluation time discrepancy/评估时间差异](#-evaluation-time-discrepancy评估时间差异)
34
34
- [> `is` is not what it is!](#-is-is-not-what-it-is)
35
35
- [> A tic-tac-toe where X wins in the first attempt!](#-a-tic-tac-toe-where-x-wins-in-the-first-attempt)
36
36
- [> The sticky output function](#-the-sticky-output-function)
@@ -375,7 +375,7 @@ for i, some_dict[i] in enumerate(some_string):
375
375
376
376
---
377
377
378
-
### > Evaluation time discrepancy
378
+
### > Evaluation time discrepancy/评估时间差异
379
379
380
380
1\.
381
381
```py
@@ -411,13 +411,13 @@ array_2[:] = [1,2,3,4,5]
411
411
[1,2,3,4,5]
412
412
```
413
413
414
-
#### 💡 Explanation
414
+
#### 💡 说明
415
415
416
-
-In a [generator](https://wiki.python.org/moin/Generators) expression, the `in`clause is evaluated at declaration time, but the conditional clause is evaluated at runtime.
417
-
-So before runtime, `array`is re-assigned to the list`[2, 8, 22]`, and since out of `1`, `8`and`15`, only the count of `8`is greater than `0`, the generator only yields`8`.
418
-
-The differences in the output of `g1` and `g2` in the second part is due the way variables `array_1` and `array_2` are re-assigned values.
419
-
-In the first case, `array_1` is binded to the new object`[1,2,3,4,5]`and since the `in` clause is evaluated at the declaration time it still refers to the old object`[1,2,3,4]` (which isnot destroyed).
420
-
-In the second case, the slice assignment to `array_2` updates the same old object`[1,2,3,4]` to `[1,2,3,4,5]`. Hence both the `g2` and `array_2` still have reference to the same object (which has now been updated to`[1,2,3,4,5]`).
0 commit comments