Returning functions in Python

Python's functions can not only return various data types, but also return a function

Python's function name/variable name is a bit like a reference in Java, all of which point to a certain memory area

So Python can return a function

For example L=[1,2,3,4]:

def multiList(L):
    def myReduce():
        def f(x,y):
           return x*y
        return reduce(f,L)
    return myReduce()

As for the reduce() function, please refer to Python's map() and reduce() functions

operation result:

24

Note: Personal study records are for reference only, if there is any error, please leave a message

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326568013&siteId=291194637