Python Decorators Tutorial: how Python decorators work

preview_player
Показать описание
This Python Decorators Tutorial video is about what are decorators in Python and how Python decorators work. The video is for absolute beginners with simple examples.

I started with creating a background for a Python decorator usage, and specified the problems that decorators solve.

Follow me @:

✴️✴️✴️ Web Scraping course ✴️✴️✴️
is available via Patreon here:

or its landing:

In this video reviewed three versions of Python decorators:
1. A simple decorator for a function that not accepting any arguments
2. A decorator for a function that accepting some arguments
3. A decorator that has own arguments for a function that accepting some arguments

And a small bonus:
- A small demo that list comprehensions are faster than a FOR loop for generating lists.

Python Decorators are possible because of Python functions are first class objects.
First class object means that:
- functions are real objects that even have own methods
- a function can be assigned as a value to variables
- a function can be sent to another function as an argument (like it happens with the map() function)
- we can return function objects as a returning value of another function
- inside a function we can define another... nested function.

Timecodes:
7:57 - the beginning of explanation.
12:35 - Python decorators for function with arguments
18:48 - Python decorators with arguments for function that have own argument

➥➥➥ SUBSCRIBE FOR MORE VIDEOS ➥➥➥
Never miss a new video.

This Python decorators tutorial is about how decorators work in Python.

Python Decorators Tutorial: how Python decorators work:

#python #pythontutorial #redeyedcoderclub
Рекомендации по теме
Комментарии
Автор

What video should I make next? Any suggestions? *Write me in comments!*
Follow me @:

Help the channel grow! Please Like the video, Comment, SHARE & Subscribe!

RedEyedCoderClub
Автор

9:20 - great clarification! I finally understand difference between myfunc & myfunc(). Subscribed!

EnglishRain
Автор

thank you very much for this sir. Can you post a video specifically about the @property decorator? I do not understand it and there seems to be very little people who explain it on here. thank you again

deneenb
Автор

In response to the last part of the video where you talk about if the function AND the decorator take arguments:


What if I don't know the value of n before I've run the arguments through timeit? i.e. I want to do something with the argument passed to the decorator and then pass the result of that to the function when called in the wrapper.


Is that not possible?

petrockspiracy
Автор

Can we use decorator inside decorator, what its use case? This question was asked to me . How to respond this question

pandaparas