Addition overloading in Python behaviour x+y vs y+x

后端 未结 1 617
一个人的身影
一个人的身影 2021-01-27 17:46

In Python if I have

class Foo:
  def __add__(self, other):
    return 123

then I can do Foo()+1 and get 123.

But if I do <

相关标签:
1条回答
  • 2021-01-27 18:12

    Implement the __radd__() method as well.

    0 讨论(0)
提交回复
热议问题