Python 中的 /= 运算符是什么意思?

What does the /= operator mean in Python?

运算符 /=(斜线等于)在 Python 中的含义是什么?

我知道 |= 是集合运算符。不过我以前没见过 /=

它是 /= 的赋值运算符 shorthand。

示例:

x = 12
x /= 3
# equivalent to
x = x / 3

如果您使用help('/='),您可以获得该语法风格支持的全部符号(包括但不限于+=-=*=),我强烈建议这样做。

这是一个用于浮点除法的增强赋值运算符。相当于

x = x / 3

根据 Makota 上面的回答,以下内容由 python 3 提供,包括目标类型和运算符,请参阅 https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements 了解更多信息:

augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)

augtarget ::= 标识符 |属性参考 |订阅 |切片

augop ::= "+=" | “-=” | "*=" | “@=” | “/= | “//=” | "%=" | "**=" | ">>=" | “<<= | "&=" | “^=” | "|="