728x90
반응형
데코레이터
def deco(func):
def wrapper():
print('*' * 10)
func()
print('*' * 10)
return wrapper
def hello():
print('hello!')
decorated = deco(hello)
hello()
decorated()
# **********
# hello!
# **********
- @기호를 통해 보다 쉽게 사용할 수 있다.
def deco(func):
def wrapper():
print('*' * 10)
func()
print('*' * 10)
return wrapper
@deco
def hello():
print('hello!')
hello()
# **********
# hello!
# **********
'Python 활용하기' 카테고리의 다른 글
[자료구조] Priority Queue (0) | 2025.02.25 |
---|---|
행렬의 곱셈 (0) | 2023.11.06 |
변수의 범위 (0) | 2023.10.24 |
2차원 리스트 생성 (0) | 2023.07.31 |
[자료구조] 트라이(Trie) (0) | 2023.01.19 |