What does the “at” (@) symbol do in Python?

前端 未结 12 1127
萌比男神i
萌比男神i 2020-11-22 01:57

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 Goo

12条回答
  •  执笔经年
    2020-11-22 02:38

    An @ symbol at the beginning of a line is used for class, function and method decorators.

    Read more here:

    PEP 318: Decorators

    Python Decorators

    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. Scroll down to see other answers that address that use of @.

提交回复
热议问题