Python 中的“@="符号是什么? [英] What is the '@=' symbol for in Python?
问题描述
我知道 @
是用于装饰器的,但是 @=
在 Python 中是什么?是否只是为一些未来的想法保留?
I know @
is for decorators, but what is @=
for in Python? Is it just reservation for some future idea?
这只是我在阅读 tokenizer.py
时的众多问题之一.
This is just one of my many questions while reading tokenizer.py
.
推荐答案
来自 文档:
@
(at) 运算符旨在用于矩阵乘法.没有内置的 Python 类型实现此运算符.
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__
.
The @
operator was introduced in Python 3.5. @=
is matrix multiplication followed by assignment, as you would expect. They map to __matmul__
, __rmatmul__
or __imatmul__
similar to how +
and +=
map to __add__
, __radd__
or __iadd__
.
这篇关于Python 中的“@="符号是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!