mirror of
https://github.com/satwikkansal/wtfpython
synced 2024-11-22 11:04:25 +01:00
Update Example: Same operands, different story!
* Clarifies that the difference between `a+=b` and `a=a+b` is not universal
This commit is contained in:
commit
0492157664
6
README.md
vendored
6
README.md
vendored
@ -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.
|
||||
|
||||
---
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user