-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
complex-numbers: operator overloading #724
Comments
@SaschaMann, good point, thanks! I totally agreed. It* will showcase use of Python`s magic methods an operator overloading (Java for example does not have such luxury) in action. Perhaps it would be a good idea to include a hint explaining what it is in the exercise as well |
|
Hi, how do I override |
@susg Hi! If you are interested in working on this, please create a pull request to claim the issue. There is no operator to override for
For more info on overloading operators, see below: @m-a-ge susg raised a good point; in Python 2, the operator for |
Replace add, sub, mul, div, with __add__, __sub__, __mul__, __truediv__ to showcase use of Pythons's magic methods on operator overloading. Added __eq__ in example.py to compare two ComplexNumber objects. Closes exercism#724
As this is no longer pending resolution of #1057, I am removing the pinned label. |
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
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
* complex-numbers: operator overloading 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 #724 * override abs with __abs__ * add hints.md and regenerate README
The complex-number exercise testsuite and example use methods
add
,mul
etc. instead of the operators__add__
,__mul__
. Using the latter, one could doComplexNumber(1, 2) + ComplexNumber(3, 4)
instead ofComplexNumber(1, 2).add(ComplexNumber(3, 4))
which might be a more natural/pythonic way to write these. Perhaps changing it to the operator version would make this exercise a bit more interesting and applicable to "real life" use cases?The text was updated successfully, but these errors were encountered: