The function name is essentially the memory address of the function

def wrapper() :
    pass

print(wrapper)
Copy the code

1. What is a quote?

When we define a=1, we’re going to create a memory space to hold 1, and then we’re going to use the name of a variable to hold a reference to the memory address of 1, which is like a pointer in C, so you can think of a reference as an address, and a holds the address of 1, and A holds a reference to 1.

When we define a function in our code, the system allocates a memory space to hold the function’s internal variables and function name. The wrapper is just a variable name that holds the address in the function’s memory. We can use x = wrapper,y = wrapper. This is equivalent to assigning the wrapper address to x and y, so that x and y refer to the wrapper function. We can use x() and y() to call the Wrapper function, which is actually a function, and x, y, and wrapper variables hold the address of the same function.

2. The function name stores the memory address of the function

def func() :
    print(1)

print(func)
#<function func at 0x000001AFABE2C8C8>
Copy the code

3. Assign the function name to other variables

def func() :
    print(1)
#Python Learning exchange QQ group: 531509025
x = func
y = func
x()
y()
Copy the code

4. Function names can be elements of container classes

def fun() :
    print(111)
def fun1() :
    print(222)
def fun2() :
    print(333)

l1 = [fun,fun1,fun2]
for i in l1:
    i()
Copy the code

5. Function names can be used as arguments to other functions

F1 = f = f() internal address -> f1()


def f() :
    print(123)
#Python Learning exchange QQ group: 531509025
def fun(f) :
    f1 = f
    f1()

fun(f)
Copy the code

6. Function names can be used as return values of other functions

def func() :
    print(123)

def fun(f) :
    return f

ret = fun(func)
ret()
Copy the code