函数-嵌套函数

#嵌套函数

def func1():

  print(‘alex’)

  def func2():

    print(‘eric’)

#1. func()

func1()

执行结果:

alex

#2 .func()

def func1():

  print(‘alex’)

  def func2():

    print(‘eric’)

  func2()

#1. func()

func1()

执行结果:

alex

eric

1.函数内部可以再次定义函数

2. 执行需要被调用

函数变量取值是有内至外一层层往上找!

猜你喜欢

转载自www.cnblogs.com/kingforn/p/10891431.html