|
449 | 449 |
|
450 | 450 | ```py
|
451 | 451 | >>> a, b = 257, 257
|
452 |
| ->> a is b |
| 452 | +>>> a is b |
453 | 453 | False
|
454 | 454 | ```
|
455 | 455 |
|
@@ -917,7 +917,7 @@ array_4 = [400, 500, 600]
|
917 | 917 | - 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.
|
918 | 918 | - 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`.
|
919 | 919 | - 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.
|
920 |
| -- 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 is not destroyed). |
| 920 | +- In the first case, `array_1` is bound 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 is not destroyed). |
921 | 921 | - 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]`).
|
922 | 922 | - Okay, going by the logic discussed so far, shouldn't be the value of `list(gen)` in the third snippet be `[11, 21, 31, 12, 22, 32, 13, 23, 33]`? (because `array_3` and `array_4` are going to behave just like `array_1`). The reason why (only) `array_4` values got updated is explained in [PEP-289](https://www.python.org/dev/peps/pep-0289/#the-details)
|
923 | 923 |
|
@@ -1841,9 +1841,9 @@ NameError: name 'e' is not defined
|
1841 | 1841 |
|
1842 | 1842 | **Output:**
|
1843 | 1843 | ```py
|
1844 |
| - >>>f(x) |
| 1844 | + >>> f(x) |
1845 | 1845 | UnboundLocalError: local variable 'x' referenced before assignment
|
1846 |
| - >>>f(y) |
| 1846 | + >>> f(y) |
1847 | 1847 | UnboundLocalError: local variable 'x' referenced before assignment
|
1848 | 1848 | >>> x
|
1849 | 1849 | 5
|
@@ -2753,7 +2753,7 @@ def similar_recursive_func(a):
|
2753 | 2753 |
|
2754 | 2754 | * As for the fifth snippet, most methods that modify the items of sequence/mapping objects like `list.append`, `dict.update`, `list.sort`, etc. modify the objects in-place and return `None`. The rationale behind this is to improve performance by avoiding making a copy of the object if the operation can be done in-place (Referred from [here](https://docs.python.org/3/faq/design.html#why-doesn-t-list-sort-return-the-sorted-list)).
|
2755 | 2755 |
|
2756 |
| -* Last one should be fairly obvious, mutable object (like `list`) can be altered in the function, and the reassignation of an immutable (`a -= 1`) is not an alteration of the value. |
| 2756 | +* Last one should be fairly obvious, mutable object (like `list`) can be altered in the function, and the reassignment of an immutable (`a -= 1`) is not an alteration of the value. |
2757 | 2757 |
|
2758 | 2758 | * Being aware of these nitpicks can save you hours of debugging effort in the long run.
|
2759 | 2759 |
|
|
0 commit comments