Python 中的 /= 运算符是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32490721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the /= operator mean in Python?
提问by ShanZhengYang
What does the operator /=(slash equals) mean in Python?
/=Python中的运算符(斜杠等于)是什么意思?
I know |=is a set operator. I have not seen /=previously though.
我知道|=是一个集合运算符。不过我以前没见过/=。
采纳答案by Makoto
It's an assignment operator shorthand for /and =.
它是/and的赋值运算符简写=。
Example:
例子:
x = 12
x /= 3
# equivalent to
x = x / 3
If you use help('/='), you can get the full amount of symbols supported by this style of syntax (including but not limited to +=, -=, and *=), which I would strongly encourage.
如果你使用help('/='),你可以得到全额通过这种风格语法的支持符号(包括但不限于+=,-=和*=),我强烈鼓励。
回答by Jacob Helfman
It's an augmented assignment operator for floating point division. It's equivalent to
它是浮点除法的增强赋值运算符。它相当于
x = x / 3
Per Makota's answer above, the following is provided by python 3, including the target types and operators, see https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statementsfor more info:
根据上面 Makota 的回答,python 3 提供了以下内容,包括目标类型和运算符,请参阅https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements了解更多信息:
augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)
增广分配_stmt ::= augtarget augop (expression_list | yield_expression)
augtarget ::= identifier | attributeref | subscription | slicing
augtarget ::= 标识符 | 属性引用 | 订阅 | 切片
augop ::= "+=" | "-=" | "*=" | "@=" | "/=" | "//=" | "%=" | "**=" | ">>=" | "<<=" | "&=" | "^=" | "|="
augop ::= "+=" | "-=" | "*=" | "@=" | "/=" | "//=" | "%=" | "**=" | ">>=" | "<<=" | "&=" | "^=" | “|=”

