![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 # 9 2 # 1 * 2 * 3 * ... 9 3 4 5 6 # 9! = 9 * 8! 7 # 8 * 7! 8 # 7 * 6! 9 # .... 10 # 1! = 1 11 12 # 功能: 如果是不直接知道结果的数据, 就进行分解 9 9 * 8! 8 = 13 # 如果说, 直接知道结果的数据, 就直接返回 1! = 1 14 def jiecheng(n): 15 if n == 1: 16 return 1 17 # n != 1 18 return n * jiecheng(n - 1) 19 20 result = jiecheng(5) 21 print(result)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 # 2 # bbbbb = 10 3 # 4 # def test(): 5 # a = 1 6 # print(b) 7 # def test2(): 8 # print(a) 9 # c = 111 10 # print(b) 11 # 12 # 13 # # print(b) 14 # test() 15 # 16 # import os 17 # 18 # os.remove() 19 # 20 # xxx.remove() 21 # 22 # __name__ 23 24 25 # if True: 26 # a = 10 27 # 28 # print(a) 29 30 # -----------------------局部变量 全局变量---------------------------- 31 # a = 999 32 # 33 # def test(): 34 # # a = 1 35 # # a = 2 36 # print(a) 37 # def test2(): 38 # # nonlocal a 39 # # a = 10 40 # print(a) 41 # test2() 42 # print(a) 43 # 44 # test() 45 46 # print(a) 47 # a = 999 48 # b = 10 49 # 50 # def test(): 51 # # 这里如果, 直接使用赋值表达式, 赋值给一个变量, 其实是代表,定义一个新的变量 52 # global a 53 # a = 6 54 # print(a) 55 # # def tes2(): 56 # # nonlocal a 57 # # a = 77 58 # b = 10 59 # c = 0 60 # print(locals()) 61 # print(globals()) 62 # # print(a) 63 # test() 64 # # print(a) 65 # 66 # 67 # print(b) 68 69 70 71 g_a = 1 72 g_b = 10 73 def test(): 74 print(g_a) 75 print(g_b) 76 77 test()