No, you can’t use multiple arguments. Python executes each +
operator separately, the two +
operators are distinct expressions.
For your example, object + 1 + 2
really is (object + 1) + 2
. If (object + 1)
produces an object that has an __add__
method, then Python will call that method for the second operator.
You could, for example, return another instance of A
here:
>>> class A: ... def __init__(self, val): ... self.val = val ... def __repr__(self): ... return f'<A({self.val})>' ... def __add__(self, other): ... print(f'Summing {self} + {other}') ... return A(self.val + other) ... >>> A(42) + 10 Summing A(42) + 10 <A(52)> >>> A(42) + 10 + 100 Summing A(42) + 10 Summing A(52) + 100 <A(152)>
Related Posts:
- Python function overloading
- Creating a static class with no instances
- Are static class variables possible in Python?
- Does Python have “private” variables in classes?
- AttributeError: ” object has no attribute ”
- Python calling method in class
- AttributeError: ‘datetime’ module has no attribute ‘strptime’
- The difference between ‘+=’ and ‘=+’?
- How do you call an instance of a class in Python?
- List attributes of an object [duplicate]
- How to print instances of a class using print()?
- How to extend a class in python?
- How to implement a binary search tree in Python?
- How can I create an object and add attributes to it?
- Accessing a class’ member variables in Python?
- How do operator.itemgetter() and sort() work?
- How to iterate over rows in a DataFrame in Pandas
- How to convert list to string [duplicate]
- How to uninstall a package installed with pip install –user
- numpy max vs amax vs maximum
- TypeError: ‘str’ object is not callable (Python)
- ValueError: invalid literal for int() with base 10: ”
- Print string to text file
- Does Python have an ordered set?
- Asking the user for input until they give a valid response
- Print a list in reverse order with range()?
- Configuring so that pip install can work from github
- Proper way to declare custom exceptions in modern Python?
- TypeError: ‘float’ object not iterable
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Importing class from another file [duplicate]
- Pandas group-by and sum
- Python List vs. Array – when to use?
- Changing the “tick frequency” on x or y axis in matplotlib?
- TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’
- Remove all special characters, punctuation and spaces from string
- Plot pie chart and table of pandas dataframe
- ModuleNotFoundError: No module named ‘matplotlib’
- “inconsistent use of tabs and spaces in indentation”
- Pandas ‘count(distinct)’ equivalent
- How can I flush the output of the print function?
- No module named pkg_resources
- Opening a .ipynb.txt File
- How do I remove all packages installed by PIP?
- How do I find the distance between two points?
- How do I calculate percentiles with python/numpy?
- How do I remove a substring from the end of a string?
- Selecting with complex criteria from pandas.DataFrame
- How can I download Anaconda for python 3.6
- django:django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet
- Replace and overwrite instead of appending
- module ‘pandas’ has no attribute ‘rolling_mean’
- How to select a drop-down menu value with Selenium using Python?
- ValueError: x and y must be the same size
- TypeError: ‘int’ object does not support item assignment
- Loading a file with more than one line of JSON into Pandas
- SystemError: new style getargs format but argument is not a tuple?
- How to convert bytearray to string in python
- Subtracting two lists in Python
- Python Subprocess: Too Many Open Files
- urllib2.HTTPError: HTTP Error 403: Forbidden
- .write not working in Python
- Install Plotly in Anaconda
- ValueError: zero length field name in format in Python2.6.6
- Python NameError, variable ‘not defined’
- Cannot import cv2 in python in OSX
- numpy-equivalent of list.pop?
- How to get row number in dataframe in Pandas?
- Difference between Python’s Generators and Iterators
- “Unorderable types: int() < str()"
- Python ImportError: No module named wx
- Declaring a multi dimensional dictionary in python
- How do I compute derivative using Numpy?
- No module named utils error on compiling py file
- Convert Pandas Column to DateTime
- ImportError: cannot import name NUMPY_MKL
- Disable / Enable Button in TKinter
- Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support
- How do I find the time difference between two datetime objects in python?
- How to strip a specific word from a string?
- Meaning of list[-1] in Python
- Tkinter error: Couldn’t recognize data in image file
- How to install Openpyxl with pip
- getting ZeroDivisionError: integer division or modulo by zero
- Iterating through list of list in Python
- Installing scipy for python 2.7
- Installing MySQL-python causes command ‘clang’ failed with exit status 1 on Mac OS 10.13.15
- Get difference between two lists
- how to build .exe for python 3.5+, 3.6 if possible?
- How to query as GROUP BY in django?
- What is the most efficient way to store a list in the Django models?
- Convert list of dictionaries to a pandas DataFrame
- How to read html from a url in python 3
- Set variable in jinja
- Python how to write to a binary file?
- How to download a file via FTP with Python ftplib
- How do I restart a program based on user input?
- Python Pandas : pivot table with aggfunc = count unique distinct
- Flask Value error view function did not return a response [duplicate]