函数的嵌套
一、函数的嵌套定义
函数套函数
def f1():
def f2():
print('from f2')
return f2
abc = f1() # f1()拿到函数的返回值,函数的返回值是f2, abc就相当于f2
abc()
二、函数的嵌套调用
#比较4个数的大小
def self_max(x,y):
if x>y:
return x
else:
return y
def self_4_max(x,y,p,q):
res1=self_max(x,y)
res2 = self_max(p,q)
res3 = self_max(res1,res2)
return res3
print(self_4_max(1,20,50,90))
-----------------------------------------------------
90