Python 技巧:装饰器(Decorator)基础
作者:野牛程序员:2025-12-22 11:05:59python阅读 2004
Python 技巧:装饰器(Decorator)基础
# /*
# Python 技巧:装饰器(Decorator)基础
# --------------------------------------------------------
# 功能:
# - 演示装饰器最常见的写法
# - 展示函数增强的基本思想
# */
print("示例一:装饰器基础")
def logger(func):
def wrapper(*args, **kwargs):
print("执行函数:", func.__name__)
return func(*args, **kwargs)
return wrapper
@logger
def hello():
print("Hello Python")
hello()
print("-" * 50)
#
# 示例一:装饰器基础
# 执行函数: hello
# Hello Python
# --------------------------------------------------野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892

