|
|
|
|
|
by HelloNurse
249 days ago
|
|
This type confusion would have been identical with a plain function, __add__ is only syntactic sugar: class MyNum(int):
def ten_times_sum (self, other):
return (self+other)* 10
n = MyNum(12)
a = 45
print(n.ten_times_sum(a))
Compare with, for example, fouling the state of output streams from operator>> in C++. |
|
Operator overload is indeed syntactic sugar for function calls, regardless of the language.
By the way, you can overload >> in Python via rshift(), or __rshift__() methods.