Tuesday, May 19, 2026

Python Material - Part - 22 - Decorator

What is a Decorator?

A decorator is a wrapper around a function — it adds extra functionality without changing the original function!

Think of it like: Sprinkling chocolate powder on coffee — The coffee is the same, but with extra decoration on top! 🍫

Basic Decorator example

def
surendra(func): # function తీసుకుంటుంది
def wrapper():
print(
"Before function runs")
func() # original function execute
print("After function runs")
return wrapper # wrapper return చేస్తుంది


@surendra
def students_info():
print(
"Meera sindhu")
print(
"Narendra Boyina")

students_info() # calling function


Advanced Decorator example:

No comments:

Post a Comment