From 043b83a7223d64728292c5de3cd05cc22e5fab58 Mon Sep 17 00:00:00 2001 From: bwduncan Date: Fri, 29 Oct 2021 20:52:07 +0100 Subject: [PATCH] Minor README fixups --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cb9c684..e9f33c6 100644 --- a/README.md +++ b/README.md @@ -449,7 +449,7 @@ True ```py >>> a, b = 257, 257 ->> a is b +>>> a is b False ``` @@ -917,7 +917,7 @@ array_4 = [400, 500, 600] - 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. - 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`. - 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. -- 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). +- 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). - 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]`). - 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) @@ -1841,9 +1841,9 @@ NameError: name 'e' is not defined **Output:** ```py - >>>f(x) + >>> f(x) UnboundLocalError: local variable 'x' referenced before assignment - >>>f(y) + >>> f(y) UnboundLocalError: local variable 'x' referenced before assignment >>> x 5 @@ -2753,7 +2753,7 @@ def similar_recursive_func(a): * 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)). -* 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. +* 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. * Being aware of these nitpicks can save you hours of debugging effort in the long run.