complex-numbers: operator overloading#1098
Conversation
Replace add, sub, mul, div, with __add__, __sub__, __mul__, __truediv__ to showcase use of Pythons's magic methods on operator overloading. Add __eq__ in example.py to compare two ComplexNumber objects. Closes exercism#724
cmccandless
left a comment
There was a problem hiding this comment.
It would be helpful for users not familiar with magic methods to provide a hint in a hints.md file (see the implementation for simple-linked-list for an example. Note that the contents of hints.md must also appear in the exercise README.md.
| def __truediv__(self, other): | ||
| pass | ||
|
|
||
| def abs(self): |
There was a problem hiding this comment.
This can also be overloaded as __abs__.
|
This issue has been automatically marked as |
|
@N-Parsons As this PR abandoned, but nearly finished, I went ahead and made the requested change. If there is nothing else, go ahead and merge. |
|
This issue has been automatically marked as |
Replace
add,sub,mul,div, with__add__,__sub__,__mul__,__truediv__to showcase use of Pythons's magic methods onoperator overloading.
Add
__eq__in example.py to compare twoComplexNumber objects.
Closes #724
Closes #983 (duplicate PR by same author)