0% found this document useful (0 votes)
10 views1 page

Decorator 1

Decorators in Python are functions that take another function as an argument to extend its functionality without altering the original function. They allow for extensibility and can be used in decorator chaining to add multiple functionalities, such as addition and multiplication, to a single function. This approach enhances code flexibility and maintainability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Decorator 1

Decorators in Python are functions that take another function as an argument to extend its functionality without altering the original function. They allow for extensibility and can be used in decorator chaining to add multiple functionalities, such as addition and multiplication, to a single function. This approach enhances code flexibility and maintainability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Decorators in Python:

what are decorators in python

Decorator is a function that can take another function as an argument and extend
its functionality
and return the modified function with extended functionality

def divisionofNumbers(number1, number2):


result = number1/number2
return result

result = divisionofNumbers(4,2)
print(result)

result1 = divisionofNumbers(4,0)
print(result)

Decorators are used to add or modify the existing functionality without changing
the original function

This is an example of extensibility


extensibility: without modifying the existing code, we can add new functionality

we can also add multiple decorators also to single function


this is called decorator chaining

add new functionalities like addition, multiplication to the existing function we


can use decorator chaining

You might also like