A. Function objects: Functions are the first class of objects, that is, functions can be passed as data
1. Can be referenced
def foo (): Print (' fromfoo') func=foo ##foo值赋给了funcprint( Foo) ##<function foo at 0x006e4108>print(func) # #<function foo at 0x006e4108>func () ##foo值赋给了func, so you can refer directly ()
2. Can be passed as parameters
def foo (): Print ('fromfoo111111') def Bar (func): Print (func) func () bar (foo)
3. The return value can be a function
def foo (): Print ('fromfoo') def Long (func): return FUNCF=long (foo)print(f) f ()
4. Elements that can be used as container types
def foo (): Print (' fromfoo'= {'fuck': foo}Print (dic['fuck') dic['fuck'] ()
defSelect (SQL):Print('------>select')defUpdate (SQL):Print('------>update')defDelete (SQL):Print('------>delete')defInsert (SQL):Print('------>insert') Fun_dit={ 'Select': SELECT,'Update': Update,'Delete':d elete,'Insert': Insert}defMain (): whileTrue:sql= Input ('>>>:'). Strip ()if notSql:ContinueL=sql.split () cmd=L[0]ifCmdinchFun_dit:fun_dit[cmd] (l) Main ()
Two. Nesting of functions
1. Nested calls to functions
def max2 (x, y ): return if Else y def max4 (a,b,c,d): res1=Max2 (A, b) res2=max2 (res1,c) res3=max2 ( res2,d) return res3print(max4 (10,80,31,20))
2. Function Nesting Definitions
def F1 (): def F2 (): Print ('fromfoo f2') def f3 (): Print ('fromfoo f3') f3 () F2 () F1 ()
Day04-python Basic Functions