python - function 13, object-oriented

1. Can be cited

def foo():
    return ('hello world!')
a=foo
print(a())
View Code

2. Can be used as return value

def outer():
    def inner():
        print(111)
    return inner
y=outer()
and()
# todo If you change 111 to inner, add a 
# todo print(y) at the end of the function to print two identical memory addresses 
# todo so y is equivalent to inner, so y()=inner()
View Code

3. Can be used as a parameter

def foo():
    print('hello world!')
def foo2(b):
    print(b)
    b()
foo2(foo)
# todo foo2 pass in foo and print the address, b is the same as the address of foo and then add a () call, 
# todo will output hello world!
View Code

4. Can be used as a container type element

def foo():
    return ('hello world!')
l={'foo':foo}
y =l[ ' foo ' ]()
 print (y)
 # todo y=l['foo'] to get the function named foo, that is to say y=foo, then add parentheses to call
View Code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324938133&siteId=291194637