python学习笔记(2) 函数的嵌套

def max(a,b):

  return a if a >b else b

def the_max(x,y,z):

  c = max(x,y)

  return max(c,z)

print(the_max(1,2,3))

#一个简单的嵌套例子

声明全局变量 global

声明上几层中最近那一层中的局部变量 nonlocal

def func():

  print(123)

func2 = func

lis = [func,func2]

for i in lis:

  i()

#这个例子表明函数名可以作为容器类型的元素

猜你喜欢

转载自www.cnblogs.com/farion/p/9859154.html
今日推荐