函数嵌套

函数的嵌套调用:在一个函数内部又调用其他函数

def fun(x,y):
    if x>y:
        return x
    else:
        return y
    
def func(a,b,c,d,e):
    rea=fun(a,b)
    rea1=fun(rea,c)
    rea2=fun(rea1,d)
    rea3=fun(rea2,e)
    return rea3

res=func(1,2,3,4,5)
print(res)

函数的嵌套定义:在函数内又定义了其他函数

def func():
    def foo():
        print('hello')

    print(foo)
    foo()
    x=1
    print(x)

func()

猜你喜欢

转载自www.cnblogs.com/xiamenghan/p/9709853.html