Enter real and imaginary part of complex No - 1
Enter real and imaginary part of complex No - 2
Modulas of complex Number A: 5.0
Python provides ability to override inbuilt arithmetic methods like __add__(),__sub__(), etc methods. It is similar to overriding __str__() method to print formatted output(like we have done in above code).For more detail refer this.
What happens internally when we perform + operation between two objects(Remember primitive integer is object in python)?- When we sum two objects in Python, like
a + b
the __add__ method of the a object is called: a.__add__(b)
it means that we can control the result of a sum of two objects by modifying or defining our own __add__ method.