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 Comment
timgeb
Yep,
x =- 1 just looks weird.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).
1 Comment
freakish
@timgeb github.com/python/cpython/blob/… As you can see
- is parsed directly, there is no __neq__ call in case of constants.
x =- xis negating x as a number.