jxp2002 发表于 2018-8-7 12:53:05

python入门(六)装饰器的理解

  装饰器用于拓展原有函数功能的一种函数
  比如:
  

def helloWorld(fun)  def out()
  print ("======start========")
  fun()
  print ("=====end======")
  return out
  

  
@helloWorld
  
def back ()
  print ("let's go")
  

  
back()
  

  运行结果:
  

======start========  
let's go
  
=====end======
  


@%E7%AC%A6%E5%8F%B7%E6%98%AF%E8%A3%85%E9%A5%B0%E5%99%A8%E7%9A%84%E8%AF%AD%E6%B3%95%E7%B3%96%EF%BC%8C%E5%9C%A8%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0%E7%9A%84%E6%97%B6%E5%80%99%E4%BD%BF%E7%94%A8%EF%BC%8C%E9%81%BF%E5%85%8D%E5%86%8D%E4%B8%80%E6%AC%A1%E8%B5%8B%E5%80%BC%E6%93%8D%E4%BD%9C
页: [1]
查看完整版本: python入门(六)装饰器的理解