Home > Backend Development > Python Tutorial > How to use @ in python

How to use @ in python

小云云
Release: 2018-03-30 17:27:22
Original
3374 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template