第三篇:函数之嵌套

 1 #函数的嵌套调用:在调用一个函数的时,其内部的代码又调用其他的函数
 2 # def bar():
 3 #     print('from bar')
 4 #
 5 # def foo():
 6 #     print('from foo')
 7 #     bar()
 8 #
 9 # foo()
10 
11 
12 # def max2(x,y):
13 #     if x > y:
14 #         return x
15 #     else:
16 #         return y
17 #
18 # def max4(a,b,c,d):
19 #     res1=max2(a,b)
20 #     res2=max2(res1,c)
21 #     res3=max2(res2,d)
22 #     return res3
23 #
24 # print(max4(1,2,3,4))
25 
26 
27 #函数的嵌套定义:在一个函数的内部又定义了另外一个函数
28 def f1():
29     x=1
30     def f2():
31         print('from f2')
32     # print(x)
33     # print(f2)
34     # f2()
35 
36 # f1=10
37 # print(f1)
38 
39 f1()
40 # f2()
41 
42 print(x)

 

posted @ 2018-07-17 20:29  zhang.ning  阅读(207)  评论(0编辑  收藏  举报