special operator =+

K

kenny Nguyen

Hi,

Does anyone know the operator "=+"?
If you do, what special method is related to this operator?
Is it the __iadd__ method, but I think this is related to "+=" operator.

Thanks,
Kenny
 
B

bearophileHUGS

kenny Nguyen>Does anyone know the operator "=+"?

It isn't an operator, it's equivalent to = (assignment) only.

Bye,
bearophile
 
P

Peter Hansen

kenny Nguyen>Does anyone know the operator "=+"?

It isn't an operator, it's equivalent to = (assignment) only.

Though actually it would try to call the __pos__ method on the object
prior to binding it to the name on the left side. (Much as - would call
the __neg__ method if it existed.) :)

-Peter
 
S

Steve Holden

Peter said:
Though actually it would try to call the __pos__ method on the object
prior to binding it to the name on the left side. (Much as - would call
the __neg__ method if it existed.) :)
Technically one shouldn't really say "it", since the sequence can only
occur in an assignment or a keyword argument specification, and in all
cases it's actually two symbols, an "=" followed by a unary "+" operator.

regards
Steve
 
S

Steven D'Aprano

kenny Nguyen>Does anyone know the operator "=+"?

It isn't an operator, it's equivalent to = (assignment) only.

No it is not.

py> x = []
py> x =+ [1]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: bad operand type for unary +

It is equivalent to assignment followed by a unary plus.
 
P

Peter Hansen

Steve said:
Technically one shouldn't really say "it", since the sequence can only
occur in an assignment or a keyword argument specification, and in all
cases it's actually two symbols, an "=" followed by a unary "+" operator.

I think it's okay if the "it" in question is the Python interpreter, as
"it" is the thing that would be calling __pos__(). On the other hand,
trying to sort out all the definitions of "it" in the above is probably
at this point a rather Clintonesque endeavour.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,274
Messages
2,571,366
Members
48,055
Latest member
RacheleCar

Latest Threads

Top