Operator Overloading
Learn about the usability of operator overloading in Python.
We'll cover the following...
We'll cover the following...
Common operators are used for their predefined purpose and functionality. When we intend to use them for an additional purpose, we need to explicitly define their behavior for a particular class. This phenomenon is called operator overloading.
Since Complex is a user-defined class, Python doesn’t know how to add objects to this class. We can teach it how to do that by overloading the +, -, +=, and == operators, as shown below:
...