What does the python operator =-
do? I'm not asking about the -=
operator, which I realize is shorthand for x = x - value
.
3 Answers
Actually, the operator =-
does not exist. It is only = (- value)
. So the negative of the value.
Example:
>>> x =- 1
>>> x
-1
-
1
Why not test it?
In [11]: x = 1
In [12]: y = 2
In [13]: y=-x
In [14]: y
Out[14]: -1
As you can see it does nothing, but sets a negative value of the variable on the right hand side
There is no =-
operator. Depending on the context this might be two operators, e.g. x =- y
is equivalent to x = (-y)
(so there are two operators: assignment and negation) or an assignment with a negative constant: x =- 1
is equivalent to x = (-1)
(in this context -
is not an operator, it's just a negative constant).
-
@timgeb github.com/python/cpython/blob/… As you can see
-
is parsed directly, there is no__neq__
call in case of constants.– freakishCommented May 26, 2017 at 13:43
x =- x
is negating x as a number.