1

I noticed a rather strange behaviour for integers, which doesn't apply, for example, to floats or decimals:

In [205]: 10.__add__
File "<ipython-input-205-24ed61a2ee18>", line 1
10.__add__
         ^
SyntaxError: invalid syntax

This does not happen for floats or decimals:

In [211]: Decimal(10).__add__
Out[211]: <bound method Decimal.__add__ of Decimal('10')>

In [204]: 10.3.__add__
Out[204]: <method-wrapper '__add__' of float object at 0x7fb48c60f840>
elena
  • 3,740
  • 5
  • 27
  • 38

1 Answers1

11

The parser is expecting the period to be the decimal point of a float. Make it explicit to the parser what you mean.

(10).__add__
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358