器即函数

装饰即修饰,意指为其他函数添加新功能

装饰器定义:本质就是函数,功能是为其他函数添加新功能

二、装饰器需要遵循的原则

1.不修改被装饰函数的源代码(开放封闭原则)

2.为被装饰函数添加新功能后,不修改被修饰函数的调用方式

三、实现装饰器知识储备

装饰器=高阶函数+函数嵌套+闭包

四、高阶函数

高阶函数定义:
1.函数接收的参数是一个函数名

2.函数的返回值是一个函数名

3.满足上述条件任意一个,都可称之为高阶函数

  1 def name_code():
  2     print("My name is Aige!")
  3 def age_code():
  4     print("My age is 22")
  5 def property_code(func,func2):
  6     func()
  7     func2()
  8 property_code(name_code,age_code)
高阶函数之函数接收函数

相关文章:

  • 2021-08-05
  • 2022-12-23
  • 2022-02-20
  • 2021-07-08
  • 2021-08-27
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-24
  • 2021-05-18
  • 2021-10-16
  • 2021-09-06
  • 2021-12-19
  • 2021-11-24
  • 2021-08-01
相关资源
相似解决方案