Python Tutorials - Decorators Part 1 | Introduction | Functions | Example
HTML-код
- Опубликовано: 20 июн 2024
- In this Python programming video tutorial we will learn about decorators in detail.
Decorators are very powerful and useful tool in Python since it allows programmers to modify the behavior of function or class.
In this tutorial we will see what is decorators how to create it and also we will see few example.
Also to understand decorators we need to have knowledge about the functions.
Namespace and Variable Scope:
• Python Tutorials - Nam...
LEGB rule:
• Python Tutorials - LEG...
Closure:
• Python Tutorials - Clo...
#PythonProgramming #Decorators
For more free tutorials on computer programming
/ amulsacademy
/ amulsacademy
Best python lectures in RUclips.... You nailed it.. Thankuu...
Thank you :)
Did you check Telusko's one?
Thanks.
For the last two days, I watched a lot of videos on decorators. I could not understand. Then I watched your videos on variable scope, legb rule, closure and then decorators.
You explained everything so easily.
Thank you so much.
Finally I got the concepts of Decorators. Thanks❤️
Hands down the best Python Tutor on RUclips..Wow..thanks a millon..!!!..I'm doing a paid online course and I'm here as I couldn't understand certain concepts explained in the course by a highly experienced tutor..and I think, no one could explain and teach decorators better than what you have done here..thank u..a lot of respect..
Thank you :)
Great video on decorator. Looking forward for more like this!!! Thanks.
Thank you :)
Thanks for this Video, you explained decorator function very well. God bless you...
this is probably the best video .explained in detailed manner
Pleasure :)
Your teaching is simply super
It's superb video mam and your way of teaching is very nice and all the viewers who watch your video are also clear your all the concept from your video and I insist you all please wait this video it's very clear and point to point
Amuls is the best.
Hi, Amulya. The decorator concept was superb and perfect, you have presented in a very simplified way, really liked it, waiting for next videos on the same topic, as I got interest in this. Thanks
Thank you :)
I will upload it soon :)
Thanks a lot. Very well explained thr concept
You are awesome in explaining .please do continue this .You are doing a lot of people a big help. And yeah finally decorator concept was so beautifully and easily explained....really very helpful..😊
Thank you so much!
Amulya Thanks a lot .After watching a ample videos from other youtube channels finally your video cleared the concepts vividly.
You are most welcome :)
Explaining clearly and easy to understand.. Superbb
Thank you :)
you are so intelligent, not only good at coding, but also good at teaching, thank you!
Thank you :)
Very helpful session. Thanks a lot
Your explanation is really good
amulya thnks for explaining decorators u r the best teacher
Thank you so much :)
Better than any python tutorial on you tube....
Thank you :)
excellent..consolidated each and every concept in a single space..request to continue making videos on different topics in python
Thank you :)
Brilliant, thank you...
You are the Best teacher.
Thank you! 😃
the way you explained is really awesome...
Thank you :)
Great Explanation Ever I Seen !! 👍🔥
Glad to hear that! :)
Very helpful
.. thanks you..
My pleasure :)
Hi Amulya .I am new subscriber to ur channel.your explanation is very good .
best tutorial for decorator
Thank you :)
Too good mam thank you so much
Thankyou so much
I have taken Python basics course for $350 on Edureka & then I took Python for data science course with Edureka for $800Later I took few more courses on udemy for Python.All I can say is Amulya tutorials on Pythons are the best so far and all that for free, awesome.Amulya, 200+ videos on Python, kudos.One suggestion, now that you have shown so many things in Python can you please show us a few real time projects using all these concepts so we can out things together.In bits and pieces, we know how classes, methods, decorators, functions, recursive functions, shelves etc work but it will be great to see them put in real action.Do you offer any python training on how to build real time projects, I would love to take the training
Thank you so much :)
I will work on your suggestion.
I will make videos on projects, but currently i need to cover other basic concepts.
Sorry :)
Hi, This was a wonderful explanation on Decorators. i've a doubt at 18:30, why should we give as (return "give proper input), instead of return statement can we give print statement
Good Tutorial Amulya.
Thank you :)
Big fan of ur content and voice ❤️
Thank you 😊
Thanks a lot mam
Amulya's academy python videos are best.i really appreciate your videos
Glad to hear that :)
Which year you started python programming.we can easily understand your videos
I am learning a lot from amulya's academy about python
Nice video with clear explanation and easy to understand the concepts from you as always!!!
One more request ma'am : I have gone through the series of your videos and couldn't able to find out the deep and shallow copy videos.
Could you please make one video with regards to that ?
Thank you :)
Sure i will make deep and shallow copy videos asap :)
Hey Amulya what about if I have multiple nested functions what should it work
EXCELLENT
Thank you :)
your voice is very pleasing to ear..!
Thank you :)
Mam , you are awesome !!!
Thanks a lot 😊
Madam very nice explanation and pronouns I search your Chanel bottom of line good keep top
Thank you 😊
satisying explanation
like it
Thank you :)
I stucked at decorators thanks for changing it
Glad to hear that :)
when we write inner as a function i.e inner() we just need change in the undecorated function as print(str_upper) in the first example then what about the second example i.e def div(a,b)
Thanks a lottttttt
@15:01+ Setting decorator is equivalent to having a statement that redefines the function to be decorated as, for example,
print_str = str_upper(print_str) :-)
Similarly @19:00+ div = div_decorator(div) instead of decorating with @div_decorator :-)
17:38, how did the function inner (x, y) was assign the value of div(a, b) , x=a, y=b.. ?
Hello Madam, can you help me how to do this problem using decorators. I want to add three integers a,b,c and return their sum except if the numbers are between 21 to 29 i would like to count them as zero and return the sum of the other integers. how to do this?
what is the purpose of Nested function i.e (inner()) inside the decorator function?
Divide by Zero simpler version:
def decor_div(func):
def inner(x,y):
if y==0:
return "number cannot be dived by zero,give proper input"
else:
return func(x,y)
return inner
def div(a,b):
return a/b
d=decor_div(div)
print(d(8,0))
Yes, but setting decorator is equivalent to redefining div as div = decor_div(div)
Thanks,
But I like the way you say "now"
Great !! You deserve more subscribers (y)
Thank you 😊
If she appears once in a while, it may happen :-))
Can you start python - selenium
Hi, Amulya. Great explanation.
in your second example i get this error (div() missing 2 required positional arguments: 'a' and 'b') if the denominator is not 0 , eg div(4, 2), please help on this.
Give me the program please :)
@@AmulsAcademy working fine now , but I don't know what happened!!!
Thanks
Ok :)
hi mam....best explanation...................... can u help on same with singleton class from scratch
Will try :)
why can't outer itself return str1.upper()..why inner is needed ? can u please explain...
15:00 Instead of writing inner function we can directly str1.upper() in str_upper function itself right? then why are we using inner function
yes you can do it and the output will also come the same.But this thing can't be called as a decorator. For decorator, the closure property must be satisfied which say's that, to use the closure, we must have a nested function. That's why their is an inner nested function
Here the purpose is not making the string uppercase. It was taken as an example to explain decorator. A better, practically needed example could have been also added.
I couldn't understand that why do we use inner function..
Because
We can directly call the function which is to be decorated without using inner function...
So, could you tell me the requirement of the inner function...
14:18
You Can call and return upper string without defining another inner method , She is just showing example, because it is decorator will use concept of closure,
Python Decorators make an extensive use of closures as well. Go through this link www.programiz.com/python-programming/closure
Also when you use @function_name, it does not work without inner function defined
You don't need inner in this example - and her explanation for the inner at 20.23 is inaccurate imho. Closure is one reason [as pointed above] but I've found that you do need the inner function when you pass args and kwargs. The outer function will be given the name of the function being decorated and the inner wrapper will be passed the args. [ I'm new to this also, so feel free to challenge]
Mam make more videos on python
Can pls make a detailed video on Generators as well...
ok :)
New subscriber 😊
Thank you :)
hii ,
if we can change the lower case letters to upper with single function then why you use nested function in this case.
same doubt @amulya's academy
This can be simpler as :
def str_upper(func):
str1=func()
x= str1.upper()
return x
def print_str():
return "Good Morning"
print(print_str())
d=str_upper(print_str)
print(d)
Your videos are very helpful for me.But now our college start "GNU octave" coding so can you help me?????
Now i can't start sorry :)
Please mention some books for GNU octave and Python...
Damn.. tricky
Mam can you atlesast send me a link or tell me from where I can practice decorators problems.
Please I want more questions on decorators to practice
I will check :)
how are x,y related to a,b
if we want to modify a function later we can modify it later without using decorators also. Then why do we use decorators??
6:58 you can here a rooster crowing in the background (0_o)
😂😂😂😂 yes bro
ajudou mt mano slk valeu
may god give the understandable capacity, who disliked this video...
Hello ma'am, if you have any full fledge python project as a paid course do let me know...
Ok 😊
in first example you return the inner function first after that return strupdate,but in second example you return inner function in last.why?
Give me the video timing please :)
@@AmulsAcademy 6:42 and 13:57
In both example i returned inner at last.
:)
@@AmulsAcademy 😁got it..... thnx
I can't get it properly........
def str_upper(func):
def inner():
str1=func()
return str1.upper()
return inner()
def print_str():
return "good morning"
print(print_str())
str_upper(print_str)
----------------------------------------------
dear ma'am, can you please help me whether this code is right or wrong?
Dear ma'am, I also checked the following program also worked, here I have not used nested function nevertheless it works as expected.
def str_upper(func):
str1=func()
return str1.upper()
@str_upper
def print_str():
return "good morning"
print(print_str)
output: GOOD MORNING
Jesus!
Woman I bow!
GOOD at explaining ....by the way i didin't receive any watch😉
I can’t understand 😭
Hi Amul,
Your presentation and voice,both are great.
Can you please share your mail id, so that I may ask you about few doubts which I need to clarify.
Thank You
Thank you :)
amulsacademy@gmail.com
you can ask your queries in our fb page also.
:)
lots of "OKEY?" ma'm...
don't use repeatedly the word 'right' okay, it is not impressive in your explanation
Hello Madam, can you help me how to do this problem using decorators. I want to add three integers a,b,c and return their sum except if the numbers are between 21 to 29 i would like to count them as zero and return the sum of the other integers. how to do this?