Created
July 5, 2023 02:59
-
-
Save Abdurahman-hassan/fefe027e2d3f7e5beccb0261f48b38b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # Decorators | |
# | |
# # func1(func) -> inner() -> logic -> return func1 | |
# | |
# def decor(func): | |
# | |
# def inner(): | |
# print("Decorated function") | |
# func() # ordinary has been executed | |
# | |
# return inner | |
# | |
# @decor | |
# def ordinary(): | |
# print("ordinary function") | |
# | |
# | |
# # ordinary() | |
# | |
# | |
# # decorator_function_variable = decor(ordinary) | |
# # # print(decorator_function_variable) | |
# # | |
# # decorator_function_variable() | |
# ordinary() | |
# | |
# print(ordinary) | |
# print(decor(ordinary)) | |
# print(decor) | |
def smart_calc(func): | |
def inner_func(x, y): | |
print(f"I am calc {x} and {y}") | |
if y == 0: | |
print('Oops! Division by ZERO is illegal...!!!') | |
return # None | |
return func(x, y) # 20/10 = 2.0 | |
return inner_func | |
@smart_calc | |
def go_divide(a, b): | |
return a / b | |
print(go_divide(20, 2)) | |
@smart_calc | |
def go_multi(a,b): | |
return a*b | |
print(go_multi(30,10)) | |
# student_names -> url -> View -> models(database(ORM)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment