-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorators.py
More file actions
48 lines (24 loc) · 1.06 KB
/
Copy pathdecorators.py
File metadata and controls
48 lines (24 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def Hello():
print("Hello World")
def greet (fx):
def mfx():
print("Good Morning")
fx()
print("Thanks for using this function")
return mfx
@greet
def Hello():
print("hello world")
def add(a,b):
print(a+b)
Hello()
# Python Decorators
# Python decorators are a powerful and versatile tool that allow you to modify the behavior of functions and methods. They are a way to extend the functionality of a function or method without modifying its source code.
# A decorator is a function that takes another function as an argument and returns a new function that modifies the behavior of the original function.
# The new function is often referred to as a "decorated" function. The basic syntax for using a decorator is the following:
# @decorator_function def my_function():
# pass
# The @decorator_function
# Decorators are often used to add functionality to functions and methods, such as logging, memoization, and access control.
# Practical use case
# One common use of decorators is to add logging to a function. For