标签:hit 为什么 代码 lin start 结构 了解 rgs /usr
1 # /usr/bin/python3 2 #!-*-conding:UTF-8 -*- 3 #返回函数 4 5 def calc_sum(*args): 6 ax=0 7 for n in args: 8 ax=ax+n 9 return ax
1 def sum_late(*args): 2 def calc_sum(): 3 ax=0 4 for n in args: 5 ax=ax+n 6 return ax 7 return calc_sum
1 print(‘调用sum_late的结果:‘,sum_late(1,2,3,4)) 2 calc_sum=sum_late(1,2,3,4) 3 print(‘调用calc_sum的结果:‘,calc_sum())
1 调用sum_late的结果: <function sum_late.<locals>.calc_sum at 0x03141F60> 2 调用calc_sum的结果: 10
1 f1=sum_late(1,2,3) 2 f2=sum_late(1,2,3) 3 print(‘f1==f2的结果为:‘,f1==f2)
1 ==================== RESTART: C:/Users/L/Desktop/返回函数.py ==================== 2 f1==f2的结果为: False
1 # /usr/bin/python3 2 #!-*-conding:UTF-8 -*- 3 #返回函数 4 5 def count(): 6 fs=[] 7 for i in range(1,4): 8 def f(): 9 return i*i 10 fs.append(f) 11 return fs 12 f1,f2,f3=count()
1 # /usr/bin/python3 2 #!-*-conding:UTF-8 -*- 3 #返回函数 4 5 def count(): 6 fs=[] 7 for i in range(1,4): 8 def f(): 9 return i*i 10 fs.append(f) 11 return fs 12 f1,f2,f3=count() 13 print(‘f1的结果是:‘,f1()) 14 print(‘f2的结果是:‘,f2()) 15 print(‘f3的结果是:‘,f3())
1 f1的结果是: 9 2 f2的结果是: 9 3 f3的结果是: 9
1 # /usr/bin/python3 2 #!-*-conding:UTF-8 -*- 3 #返回函数 4 5 def count(): 6 def f(j): 7 def g(): 8 return j*j 9 return g 10 fs=[] 11 for i in range(1,4): 12 fs.append(f(i)) #f(i)立刻被执行,因此i的当前值被传入f() 13 return fs 14 15 f1,f2,f3=count() 16 print(‘f1的结果是:‘,f1()) 17 print(‘f2的结果是:‘,f2()) 18 print(‘f3的结果是:‘,f3())
1 ==================== RESTART: C:\Users\L\Desktop\返回函数.py ==================== 2 f1的结果是: 1 3 f2的结果是: 4 4 f3的结果是: 9
标签:hit 为什么 代码 lin start 结构 了解 rgs /usr
原文地址:http://www.cnblogs.com/DLHe/p/7791700.html