Python Decorators in Just 4 Minutes

preview_player
Показать описание
Want to learn Python decorators in just 4 minutes? 🚀

In this video, we’ll break down:
✅ What decorators are and how they work
✅ Applying multiple decorators to a function
✅ Handling arguments with *args and **kwargs

🛠️ Source Code:
import time

def measure_time(func):
def wrapper(*args, **kwargs):
func(*args, **kwargs)
print(f'Execution time: {end - start} seconds')
return wrapper

def greeting(func):
def wrapper(*args, **kwargs):
print('Hello,')
func(*args, **kwargs)
return wrapper

@greeting
@measure_time
def morning(name):
print(f'Good Morning, {name}!')

morning('John')

This step-by-step tutorial makes Python decorators simple and beginner-friendly. By the end, you'll understand how to extend your Python functions without modifying their original code.

👉 Don't forget to like, comment, and subscribe for more quick Python tutorials!

🎥 Watch now and start mastering Python today!
Рекомендации по теме
Комментарии
Автор

Bro, this tutorial is effective and clean and simple, despite the viewer numbers I’m just telling you this is dope! Keep doing these in the near future your channel will explosively grow! Everything starts with small beginning! 🎉

hahahav
Автор

This is amazing, not only did I learn about decorators, I also learned about *kwargs LOL

HanzoHasashi-bvrm
Автор

Wow, it's weird to be one of the first 1k subs to someone channel! XD I'm excited to learn a lot from you. Great tutorial, by the way! <3

MohamedEltanash
Автор

Why isnt func() being called twice since its called in both wrappers?
In this example, "Good morning" is being printed in the greetings-wrapper, but when exactly does start in measure_time get called? Is it before "Good morning" is printed in the greetings-wrapper? If not, what exactly does func() do after start = time.time()
How does Python know when func() should be called in this example?

timothytim
Автор

I can't understand y the function executes when it is not called

nccbnccb
Автор

Why I am getting 0.0 execution time?
Good morning
Execution time : 0.0 sec

MukeshKamath
Автор

Please remove the popping sound . It's distracting

darkzone
join shbcf.ru