2.
is parsed as a float, so 2.__add__
is a SyntaxError.
You can evaluate
(2).__add__(3)
instead.
In [254]: (2).__add__(3)
Out[254]: 5
More Related Contents:
- parser =3D syntax error [closed]
- How do you sum up ints in a list of list in Python 3?
- Invalid syntax when trying to run python script [closed]
- Difference between @staticmethod and @classmethod
- “is” operator behaves unexpectedly with integers
- f-strings giving SyntaxError?
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Python cannot handle numbers string starting with 0. Why?
- How do you input integers using input in Python
- Unsupported operand type(s) for +: ‘int’ and ‘str’ [duplicate]
- What is the maximum float in Python?
- Why don’t methods have reference equality?
- How do I access Class member variables in Python?
- increment int object
- Python Class Based Decorator with parameters that can decorate a method or a function
- What are the parentheses for at the end of Python method names? [duplicate]
- Why can’t attribute names be Python keywords?
- What is a “method” in Python?
- @classmethod vs @staticmethod in Python
- Why do I get the syntax error “SyntaxError: invalid syntax” in a line with perfectly valid syntax?
- How do I access Class member variables?
- Ampersand “&” syntax error running any Python script in VSCode?
- Why do parentheses in a lambda function cause syntax error on Python 3? [duplicate]
- How do I set and access attributes of a class? [duplicate]
- Why do ints require three times as much memory in Python?
- How does a Python set([]) check if two objects are equal? What methods does an object need to define to customise this?
- Python: SyntaxError: keyword can’t be an expression
- Python using methods from other classes
- Are functions objects in Python?
- Same name for classmethod and instancemethod