我知道 @
是用于装饰器的,但是 @=
在 Python 中是什么?是否只是为一些 future 的想法保留?
这只是我在阅读 tokenizer.py
时遇到的众多问题之一。
最佳答案
来自 the documentation :
The
@
(at) operator is intended to be used for matrix multiplication. No builtin Python types implement this operator.
@
运算符是在 Python 3.5 中引入的。 @=
是矩阵乘法,然后是赋值,正如您所期望的那样。它们映射到 __matmul__
、__rmatmul__
或 __imatmul__
,类似于 +
和 +=
映射到 __add__
、__radd__
或 __iadd__
。
PEP 465 中详细讨论了运算符及其背后的原理。 .
关于python - Python 中的 '@=' 符号是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27385633/