
Python Operators - bhishan
https://www.thetaranights.com/python-operators/
======
trombonechamp
The section on assignment operators is incorrect. x += y modifies the object
x, whereas x = x + y doesn't. For example,

    
    
      >> a = [1, 2, 3]
      >> b = a
      >> a += [4]
      >> a
      [1, 2, 3, 4]
      >> b
      [1, 2, 3, 4]
    

By comparison,

    
    
      >> a = [1, 2, 3]
      >> b = a
      >> a = a + [4]
      >> a
      [1, 2, 3, 4]
      >> b
      [1, 2, 3]

~~~
bhishan
This is especially true for the case of mutables. I agree it should've been
mentioned on the blog. Do you mind if I add this thread to the comments
section of the blog.

------
haney
After you're mastered all the available operators the real fun begins when you
start writing your own operator methods on classes
[http://thepythonguru.com/python-operator-
overloading/](http://thepythonguru.com/python-operator-overloading/)

The ability to override operators is one of the things I miss most from Python
when I'm forced to write javascript.

~~~
swpdkfn
There could also be mention of the "right" variants e.g. __rmul__ vs. __mul__.
[https://stackoverflow.com/questions/5181320/under-what-
circu...](https://stackoverflow.com/questions/5181320/under-what-
circumstances-are-rmul-called) gives a rough sketch of what they're about.

~~~
bhishan
This is indeed a very helpful read. Thanks for the link.

------
A2017U1
There's a few missing:

@ For matrix multiplication, equivalent to __matmul__

@= <<= >>= ^= |= Assignment operators

~~~
bhishan
Thanks for the mentions. I am sure it is helpful to anyone reading the
threads.

------
kalenx
The := is missing! No wonder Guido would leave its BDFL position!

~~~
bhishan
Isn't that for 3.8 version. I have also made a different blog around PEP 572
some time ago. I will leave the link here so it is helpful for anyone
wondering about :=

[https://www.thetaranights.com/python-assignment-
expression-p...](https://www.thetaranights.com/python-assignment-expression-
pep-572-python3-8/)

------
mabynogy
Simple and clear. Even if I don't do Python I learned some good ideas (like
the // floor operator).

~~~
bhishan
I am glad it was helpful.

