“at"是什么意思?(@) 符号在 Python 中做什么? [英] What does the "at" (@) symbol do in Python?

查看:31
本文介绍了“at"是什么意思?(@) 符号在 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.

在此处阅读更多信息:

PEP 318:装饰器

Python 装饰器

您将遇到的最常见的 Python 装饰器是:

The most common Python decorators you'll run into are:

@property

@classmethod

@staticmethod

如果你在一行的中间看到一个 @,那就是另一回事了,矩阵乘法.请参阅此答案,显示将 @ 用作二元运算符.

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屋!

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