Hi,

if I write the following:

   >>> 1+1
   2

it seems to be exactly equivalent to this:

   >>> (1).__add__(1)
   2

However, if I write invalid code and try to add a list to an int, the
errors will be different:

   >>> 1+[]
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
   TypeError: unsupported operand type(s) for +: 'int' and 'list'

   >>> (1).__add__([])
   NotImplemented

I found that operator.__add__(1, []) gives the same result as 1+[].

What is the reason behind this difference between the __add__ operator
and int.__add__?

Thank you,
Csaba
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to