简体   繁体   English

python运算子=-是做什么的?

[英]What does the python operator =- do?

What does the python operator =- do? python运算子=-做什么的? I'm not asking about the -= operator, which I realize is shorthand for x = x - value . 我不是在问-=运算符,我意识到这是x = x - value简写。

Actually, the operator =- does not exist. 实际上,运算符=-不存在。 It is only = (- value) . 它只是= (- value) So the negative of the value. 因此,负值。

Example: 例:

>>> x =- 1
>>> x
-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, eg 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). 根据上下文,这可能是两个运算符,例如x =- y x = (-y)等于x = (-y) (因此有两个运算符:赋值和求反) 具有负常数的赋值: x =- 1等于x = (-1) (在这种情况下-不是运算符,它只是一个负常数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM