Skip to content

Commit b2adfa2

Browse files
author
tuntun
committed
Python装饰器
1 parent 2102162 commit b2adfa2

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎decorator.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# coding=utf-8
2+
3+
# 定义一个装饰器
4+
def mydecorator(func):
5+
def wrapper(*args,**kw):
6+
print('hi,now is:')
7+
return func(*args,**kw)
8+
return wrapper
9+
10+
# 使用装饰器
11+
@mydecorator
12+
def now():
13+
print('2015-12-9')
14+
15+
now()
16+
17+
"""
18+
D:\learn-python>python decorator.py
19+
hi,now is:
20+
2015-12-9
21+
"""

0 commit comments

Comments
 (0)