函数的嵌套

例1:

def index():
print("from index")

def func():
index()
print("from func")
func()

定义一个index函数
定义一个func函数
调用func函数,然后跳转到那边执行语句,先执行index()语句,打印from index,然后往下执行,打印from func。


例2:
def func1(x,y): 
if x > y:
return x
else:
return y
print(func1(1,2))

定义func1函数
打印函数,然后调用func1,然后1赋值给x,2赋值给y.


例3:

 def func2(x, y, z, a):
 result = func1(x, y)
 result = func1(result, z)
 result = func1(result, a)
 return result
print(func2(1, 200000, 3, 1000)) 这是个问题?


例4:

def index():
def home():
print("from home")
home()

index()







原文地址:https://www.cnblogs.com/medigrat/p/11838370.html