From c95ba001600c57029b2b1a066ee903aa759eb783 Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Wed, 6 Sep 2017 09:12:37 +0300 Subject: [PATCH] a+=b vs a=a+b : clarify the difference is not universal Made the text say it depends on class, and rest of explanation talk of lists, not objects. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 278ba48..2ed6c73 100755 --- a/README.md +++ b/README.md @@ -858,11 +858,11 @@ a += [5, 6, 7, 8] #### 💡 Explanation: -* a += b doesn't behave the same way as a = a + b +* `a += b` doesn't always behave the same way as `a = a + b`. Classes *may* implement the op= operators differently, and lists do this. -* The expression `a = a + [5,6,7,8]` generates a new object and sets `a`'s reference to that new object, leaving `b` unchanged. +* The expression `a = a + [5,6,7,8]` generates a new list and sets `a`'s reference to that new list, leaving `b` unchanged. -* The expression `a + =[5,6,7,8]` is actually mapped to an "extend" function that operates on the object such that `a` and `b` still point to the same object that has been modified in-place. +* The expression `a + =[5,6,7,8]` is actually mapped to an "extend" function that operates on the list such that `a` and `b` still point to the same list that has been modified in-place. ---