Python 中的“@="符号是什么? [英] What is the '@=' symbol for in Python?

查看:29
本文介绍了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__.

PEP 465.

这篇关于Python 中的“@="符号是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆