Why doesn’t 2.__add__(3) work in Python?
- dunder
- float
- integer
Python parses 2. as the float 2.0, this can cause troubles when trying to use methods on integers.
>>> 2.__add__(3)
File "<stdin>", line 1
2.__add__(3)
^
SyntaxError: invalid syntax
>>> (2).__add__(3)
5