#44 Python Tutorial for Beginners | Decorators

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we will learn:
- Properties of functions
- What are decorators in Python?
- How to add extra features to a function?
- Properties of Decorators
- How to define decorators in Python?

#1
- Functions are built to perform certain tasks.

Properties of functions:-
- We can also write a code for the function inside another function.
- We can assign a function to another function in python as a function is also an object.
- A function is an instance of the Object type.
- We can store the function in a variable.
- We can also pass the function as a parameter to another function.
- A function from a function can also be returned.

#2
- Decorators are used to add extra features to the existing functions.
- Decorators can change the behaviour of an existing function at the compile itself.

#3
Properties of Decorators:-
-The outer function is called the decorator, which takes the original function as an argument and returns a modified version of it.
- Decorator contains an outer function that also takes a function as an argument.
- Inside the outer function, there is another function that takes a number of parameters as per the logic as an argument.
- Inner function contains the code for the logic that must be contained in the previously defined normal function.
- Inner function returns the values as per the required code that can be equal to the number of arguments passes in an inner function.
- Outer function return an inner function.
- In the main code, we have to call the outer function of a decorator and pass the normal function as an argument.

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

I just realized that you being physically present in the video makes such a big difference to how much attention I pay. There are tons of videos out there but your videos work for me because there is someone teaching and I can see them typing the code. The expressions and gestures also help with the learning, maybe subconsciously we understand better if knowledge transfer is backed by facial expressions. Thanks again for choosing to share your knowledge, for free!

bharathg
Автор

For those asking about the missing @, this guy actually explains what are decorators not how they are written. The syntax is unimportant if you don't know what is happening behind the scenes. The issue I observe with new programmers is that people are using stuff that they have no idea how is it working. I appreciate a great conceptual explanation.

kamilkurzynowski
Автор

You missed the most important part of the whole thing.
Using the @ syntax before the function we want to wrap is what makes decorators useful.

chrism
Автор

You are the hero of students who are eager to learn coding but can't afford to go for tution, even me.hands off to my guru

kandasamymurugadas
Автор

Ok, have to admit that this was one of the videos that was a little harder to grasp. I do get the main goal of decorators, but I am searching for more examples on how to use decorators. Your video was a great first start. Thank you!

GiovaniGalicia
Автор

I am a postgraduate in electronics field. I thought programming would be difficult, but u made it as simple as that. You are a great teacher. I have been working as a lecturer since 8 yrs . I have never seen a person like u, who teaches with so much of energy and enthusiasms. I have to learn many things from u -way of

liveinthemoment
Автор

your teaching is just awesome sir! I have seen blockchain videos and now am learning python just by seeing your python videos. its just wow! great work sir. Thank You.

kruthikahu
Автор

The best explanation I've seen so far. I'm a Python beginner (I work with Javascript).

extraxt
Автор

Why is this better than a plain, straightforward call to the original function inside a new function without all the abstraction of decorating? This video is great at explaining the mechanics, but even one sentence as to why they are superior would be great.

JasonGabler
Автор

Sir i saw the whole ad so that you get the reward😊😀

mdsadaquathussain
Автор

yes, agreed with many viewers that Navin sir haven't used '@' in the whole explanation. But we all understood the concept of Decorators through his explanation, which most of the YouTubers failed to explain.

asishraz
Автор

I just realized that you being physically present in the video makes such a big difference to how much attention I pay. There are tons of videos out there but your videos work for me because there is someone teaching and I can see them typing the code. The expressions and gestures also help with the learning, maybe subconsciously we understand better if knowledge transfer is backed by facial expressions. Thanks again for choosing to share your knowledge, for free!

uges_expo
Автор

Sir you are simply awesome. To be honest whenever I stuck for any technical topic, I immediately search on YouTube to check if there is any similar video posted by you. Your way of teaching is too good. Many thanks.

tarunseetha
Автор

Using the @syntax...
def smart_div(div):
def inner(x, y):
if x < y:
x, y = y, x

return div(x, y)
return inner

@smart_div
def div(a, b):
print(a/b)

div(2, 4)

aishwaryalaxmiveeramalla
Автор

Thank you so much for this video! I've been trying for an hour to wrap my head around decorators (pun intended :P) and this is the first video that's made sense to me.

ZyroZoro
Автор

I was confused in decorators, but this is the only video from which I really got my confusion cleared! Thanks man, Keep it up

kavnainvohra
Автор

Now I understand WHY I would use a decorator ... simply illustrated and simply understood. We all learn differently and this was concise.

asb
Автор

Really impressed! Actually I've been through 4-5 videos before, but no one cleared my doubts this easily, that also in just 7 minutes. ❣️
Really loved it.

hariomjoshi
Автор

Hey Navin, Thank you for sharing your amazing knowledge with you, This is the first video in 44 videos which I found a bit harder to grasp.

TheKapilsharma
Автор

Sir I think we should also add an "else" condition so that if we type the larger number first it will also return the answer.
def div(a, b):
print(a/b)

def smart_div(func):

def inner(c, d):
if c<d:
c, d = d, c
return func(c, d)
else:
return func(c, d)
return inner

div = smart_div(div)

div(3, 6)

samthejam