0

What does the python operator =- do? I'm not asking about the -= operator, which I realize is shorthand for x = x - value.

3
  • 1
    Have you tested it? Break it down, don't think about it as 1 operator but two: = and -. Thus x =- x is negating x as a number.
    – Andrew Li
    Commented May 26, 2017 at 13:25
  • @Roberto What do you mean "not valid python syntax"? It's completely valid.
    – Andrew Li
    Commented May 26, 2017 at 13:26
  • I could swear there is a dupe for this...
    – timgeb
    Commented May 26, 2017 at 13:26

3 Answers 3

7

Actually, the operator =- does not exist. It is only = (- value). So the negative of the value.

Example:

>>> x =- 1
>>> x
-1
1
  • 1
    Yep, x =- 1 just looks weird.
    – timgeb
    Commented May 26, 2017 at 13:27
2

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

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.