Home  >  Article  >  Backend Development  >  How to use @ in python

How to use @ in python

小云云
小云云Original
2018-03-30 17:27:223350browse

In Python functions, you will occasionally see that the previous line of the function definition is modified with @functionName. When the interpreter reads the modifier of @, it will first parse the content after @, and directly put @ on the next line. The function or class is used as the parameter of the function after @, and then the return value is assigned to the function object modified in the next line.

For example:
@a
@b
def c():
...
Python will treat the respective function results as the next one in bottom-up order The input of the function (the function above), which is a(b(c()))

def funcA(A):    
print("function A")def funcB(B):    
print(B(2))    print("function B")
@funcA@funcBdef func(c):   
 print("function C")    
 return c**2

4
function B
function A

  • Then the execution process of the entire program is funA(funB(funC))

The above is the detailed content of How to use @ in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn