decorator - Py i

This commit is contained in:
fenix 2024-02-13 14:04:17 +01:00
parent fc05b23930
commit 228eef0258
2 changed files with 18 additions and 7 deletions

11
hello_decorator.py Normal file
View File

@ -0,0 +1,11 @@
def decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
def say_whee():
print("Whee!")
say_whee = decorator(say_whee)

View File

@ -1,11 +1,11 @@
def parent():
print("Printing from parent()")
def parent(num):
def first_child():
print("Printing from first_child()")
return "Hi, I'm Elias"
def second_child():
print("Printing from second_child()")
return "Call me Ester"
second_child()
first_child()
if num == 1:
return first_child
else:
return second_child