摘要: #嵌套函数 def foo(): print('in the foo') def bar(): print('in the bar') bar() #bar()#出错,无法在外边调用,bar函数的作用范围只在foo函数之内 foo() 阅读全文
posted @ 2018-01-28 21:07 耐烦不急 阅读(117) 评论(0) 推荐(0) 编辑
摘要: import time def timer(func):#timer(test1) func=test1 def deco(): start_time=time.time() func()#run test1 stop_time=time.time() print('the func time is %s'%(stop_t... 阅读全文
posted @ 2018-01-28 21:07 耐烦不急 阅读(122) 评论(0) 推荐(0) 编辑
摘要: #匿名函数,无函数名 calc=lambda x:x*3 print(calc(3)) sum=lambda x,y,z:x+y+z print(sum(1,2,3)) ''' 高阶函数 a:把一个函数名当做一个实参传递给另一个函数(在不修改被饰函数源代码的情况下为其添加功能) b:返回值包含函数名(不修改函数的调用方式) ''' def bar(): print('... 阅读全文
posted @ 2018-01-28 21:06 耐烦不急 阅读(190) 评论(0) 推荐(0) 编辑