4 ms·
Probably nothing remotely resembling this belongs in anything remotely resembling production code, but: In [1]: class Foo: ...: def __rmul__(self, o
by owl57 9y ago
Probably nothing remotely resembling this belongs in anything remotely resembling production code, but:
In [1]: class Foo:
...: def __rmul__(self, other):
...: print("%s foos!" % other)
...:
In [2]: .42 * Foo()
0.42 foos!
- FRex 9y agoThat's very nice. I tried to go for such an example originally but I only tried __mul__ because I thought it's like in Lua where __mul gets used even if only the second operand has a custom one.