Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01aa474

Browse filesBrowse files
author
yitian
committed
添加了Python装饰器的例子。
1 parent 2671c93 commit 01aa474
Copy full SHA for 01aa474

File tree

Expand file treeCollapse file tree

1 file changed

+23
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-0
lines changed
Open diff view settings
Collapse file

‎python-samples/basic/functions.py‎

Copy file name to clipboardExpand all lines: python-samples/basic/functions.py
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,33 @@ def printFunctionAnnotation(a: str, b: int, c: list) -> None:
6767
print(f'a+b={im_a_lambda(3,4)}')
6868

6969
print('--------------文档字符串--------------')
70+
71+
7072
def function_with_documents():
7173
'''\
7274
这是一个文档字符串
7375
'''
7476
pass
7577

78+
7679
print(f'文档:{function_with_documents.__doc__}')
80+
81+
print('--------------装饰器--------------')
82+
83+
84+
def surround_decorator(func):
85+
def new_func(*args, **kargs):
86+
print('func_start')
87+
result = func(*args, **kargs)
88+
print('func_end')
89+
return result
90+
91+
return new_func
92+
93+
94+
@surround_decorator
95+
def hello():
96+
print('Hello !')
97+
98+
99+
hello()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.