“at"是什么意思?(@) 符号在 Python 中做什么? [英] What does the "at" (@) symbol do in Python?
问题描述
我正在查看一些使用 @
符号的 Python 代码,但我不知道它的作用.我也不知道要搜索什么,因为在包含 @
符号时搜索 Python 文档或 Google 不会返回相关结果.
I'm looking at some Python code which used the @
symbol, but I have no idea what it does. I also do not know what to search for as searching Python docs or Google does not return relevant results when the @
symbol is included.
推荐答案
行首的 @
符号用于类、函数和方法装饰器.
An @
symbol at the beginning of a line is used for class, function and method decorators.
在此处阅读更多信息:
您将遇到的最常见的 Python 装饰器是:
The most common Python decorators you'll run into are:
如果你在一行的中间看到一个 @
,那就是另一回事了,矩阵乘法.请参阅此答案,显示将 @
用作二元运算符.
If you see an @
in the middle of a line, that's a different thing, matrix multiplication. See this answer showing the use of @
as a binary operator.
这篇关于“at"是什么意思?(@) 符号在 Python 中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!