第三篇:函数之嵌套
1 #函數(shù)的嵌套調(diào)用:在調(diào)用一個函數(shù)的時,其內(nèi)部的代碼又調(diào)用其他的函數(shù)
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 #函數(shù)的嵌套定義:在一個函數(shù)的內(nèi)部又定義了另外一個函數(shù)
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)
?
轉(zhuǎn)載于:https://www.cnblogs.com/yspass/p/9325705.html
總結(jié)
- 上一篇: 怎么申请农行电信联名信用卡?注意这几点申
- 下一篇: 广发腾讯联名卡介绍:10分钟闪电核卡