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!
I had to watch another video that explains it to make me see that the way he explained it was also very good. I was just thrown off by the lack of the @ syntax.
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.
Yep. That would describe me. But Telusko threw in some really good information here. So basically the decorator is redefining where the 'div' object is pointing to in memory right?
So I think I agree with what @ranjeethstudio2483 is getting at, insofar as while yes, "The syntax is unimportant if you don't know what is happening behind the scenes." 1. because the video is trying to teach what a wrapper is, at the same time that it's trying to explain what a decorator is, the video is harder to follow. 2. because this video is trying to teach what a decorator is, he should teach what a decorator is in a traditional setting. I.e. "here's what a decorator will look like when you see it in code and how it works." 3. It's not unimportant if you actually want to use them in your code.
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 teaching.etc......
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!
Try code with harry for this one than jump to telusko you will get the Idea. No offence i am not comparing these two channels they both have their own taste our main intention is to grasp the concept
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.
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 TH-camrs failed to explain.
Sir you are simply awesome. To be honest whenever I stuck for any technical topic, I immediately search on TH-cam to check if there is any similar video posted by you. Your way of teaching is too good. Many thanks.
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!
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.
@Dharmesh Rajan your mindset is what I call 'chutiya' mindset. Clearly, you were never taught to give back. Tutors like Navin Reddy are teaching for free and can't you even watch a 30s ad for him? Nobody is asking how to get rid of ads here. @mohit and @MD are talking about supporting the video creator by watching ads. Get lost with your tip that no-one asked for.
@Dharmesh Rajan Hey! Take it easy. I was only discouraging 'greedy mindset'. It's not just 5 minutes but 5000 hours of experience, pre and post processing that TH-camrs put into their videos. So the feeling of being morally obliged to give back should come from within. That's what I wanted to imply. No intention of hurting anyone. I felt like you were publicising the use of vanced on a completely irrelevant and unnecessary thread. Glad that you deleted it. Peace ✌️ and happy learning :)
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.
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.
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
Hello sir, I would say your skills always astonish me .Basically I am from ECE background I am facing difficulties to understand these topics So I always used to feel low .but after watching your videos in no time I get motivated and inspired by the way you teach us.you are really doing great work.it means a lot for us.keep doing sir .thank you
Hello, I want to pursue ECE because i have interest in electronics field. Can you tell me that which coding language is most important for ECE students and if an ECE student wants a job in software company , then how can they join because they are not tought coding upto that much level which is required for software development.
Same here I am also from ECE background and this is the first language I am learning ... Thank you sir for teaching in such a way that the non it student also easily catch the concepts
def decorator(func): def new_div(a, b): if a < b: # 2/4 a, b = b, a # 4/2 return func(a, b) return new_div @decorator def div(a, b): print(a/b) div(2, 4) Nice video sir. Awesome as always. I tried using @ symbol above a function. Thank you for the awesome videos. Waiting for the new videos.
@@pallasreenivasulu4624hi, you have to use @ followed by the decorator function name which you are going to use to add the additional functionality. Then the normal function will get the functionalities of the decorator function. Hope you understand. @ is used to specify that it is a decorator function which is used to extend the functionality of a normal function, without adding the additional code. Thank you.
I have been looking for decorators and explanation. It is possible that I might not be looking at the right place or with right keywords but not a single video explained it so u effortlessly as you did. Kudos.
I'll advise you do videos on concepts such as first-class functions and closures; these would help to understand the concept of decorators better. Well done.
Since nobody wants to " 'Ruin [their] Program' " can you elaborate on when and when you should not use them, in your opinion? Prehaps give some resources?
You could also do your operation by using a HOF that just receives a function as one of its arguments. No need to return another function. An example: def division(a,b): return a/b def subtraction(a, b): return a - b def do_operation(operation, a, b): return operation(a, b) if a > b else operation(b, a) print(do_operation(division, 4, 12)) # 3.0 print(do_operation(division, 12, 4)) # 3.0 print(do_operation(subtraction, 4, 12)) # 8 print(do_operation(subtraction, 12, 4)) # 8
I was working on decorator topic and also saw 2-3 videos but was not satisfied by the logic. But your teaching made me understand the concept very easily. Thank you :)
Hello Sir thank you very much for explaining the topic. I have one question regarding how the value is passed . When the object div1 was created and then in div1(2,4) value was passed , the object div1 was an instance of the function smart_div () which was taking a function as argument only, hence how the object of smart_div which is div1 pass the value 2,4 and got accepted. It will be helpful if you clear my doubt
Sir why did we use ‘return inner’ in the end, I didn’t understand. Because ‘return func(a,b)’ is already doing the work of calling div(a,b) right? Then what is the use of return inner?
Great teaching. But you missed @ syntax. and also can you explain it little deep about why we need to use inner functions etc. I am sure we can't explain decorator concept in just 7mins.
how does inner get called and when? what i have understood is we are passing the div function as parameter to the decorator function, which is returning inner_function. Now, the inner_function object or address will be overridden in the ‘div’ because we are capturing the returned function in it. After this, whenever we call div, the execution goes to inner_function in the decorator.
Hi. If the inner(a,b) function is the one that is responsible to add/modify/influence the code of div(a,b) function, then what is the need to write the inner(a,b) function within smart_div(func) function ?
For people saying missing @ in the tutorial, please find the equivalent usage done by the tutor. You could either go with div=smart_div(div) or use @ like @smart_div on top of function div. Both are same
Mathematically speaking, decorators make sense. its essentially the concept of two functions, function f, and function g, in which the output of function f is the input of function g, which can be expressed as g(f(x)). The value of f(x) is first computed and then is used as an input for the g function, which further acts on that output, thus "decorating" it. The concept is really simple, one function taking the output of another function as its input. The confusion arises because of Python's mapping, and syntax, which quite honestly, takes a while to "register". So based on the example in this video, for instance, it supposed there is a function called div, which takes two arguments, a and b, and divides a by b, such as: a = int(input("Enter a value for a: ") b = int(input("Enter a value for b: ") def div(a, b): print(a/b) Then the function is called: div(a, b). If the user entered a value to "a", that is less than the value entered to "b", it will result in an output less than 1, and will violate the question. The way this problem can be solved, evidently, is through the use of decorators, which essentially declares a new function, such as div_new that takes the original div function as its input, and makes the necessary adjustments, such as reversing the value of a and b, or computing b/a, so that regardless of if the input value of a < b, the result will yield an integer value greater or equal to 1. Mathematically, the Python code would look like this: [code] def new_div(div(a, b)): def div(a, b): print(a/b) if a < b: print(b/a) new_div(div(a, b)) [/code] Basically, a new function new_div is created that takes the original first function div as its input. Once it goes inside the body of new_div, keeping in mind the values a, and b obtained by the client, it encounters the div function, which performs operations on a, b. Then it exits out of that function and falls into the body of new_div, encountering an if statement that tests the validity of a < b, and if it's True, then it instead prints out b/a, the reverse of a/b, which computes the quotient to a value greater than or equal to 1, without modifying the first function, thus solving the question correctly. This is the logic, though if you try to run that code the way it's written, python will throw all kinds of errors. lol. But for those trying to understand the logic, hope this helps.
Sir, my name is Krishnan.I am studying eleventh(11) standard . I have doubt whether this course is applicable for me. Kindly reply sir. Great teaching. I have doubt whether my school will teach like you and all the syllabus taught by you. I wanted to use the time judiciously during this corona time
Sir learnt a lot of Python from your videos... But sir when you were discussing about OOPs concept.. You used the words Abstraction and Encapsulation which you never explained.. A request to you sir. Please make a video on that too..
abstraction stand for abstracting the data or hide the main code of function and show the neseccary detail to user like we are using ac remote,we press the on/off button but we don't know the concept of behind this pressing button this is called abstraction,or encapsulation stands for encapsulate the method/function or variable/variables in the class together is called encapsulation
def div(a,b): return (a/b) print("step1") # step 1:'div' function will be called print(div(1,3)) print("step2") # step 2: 'div' function called and execution complete # (Step 1 & 2 has nothing to do with decorator_function) def decorator_function(func): print("step4") # step 4: 'decorator_function' execution starts. Note that 'inner_function' is still not called def inner_function(a,b): print("step7") # step 7: 'div1' function which is replica of 'inner_function' is being executed if a
Sir when we defineing the function we must be call the function that's why the function it's works.but the inner function we don't calling how it's works?
@Telusko : I did not understand the use case of this decorator here , can't we just wrap div() in side another function which will just swap the values and pass to div() ? def div(x, y): print(x/y)
# add functionality to div() without altering div() def smart_div(function): def inner(x, y): if x < y: x, y = y, x if y == 0: print("y cant be zero") return function(x, y) # calling div with new values # return function(x, y) return inner @smart_div # dec def div(a, b): print(a/b) # use '@' or 'div = smart_div(div) ' div(2, 4)
Can you guys help me understand something; If the below code also works (ignoring the ZeroDivision Error) why is there a need to add the additional inner function, as is in the tutorial? def div(a,b): print(a/b) def smartDiv(a,b): if a
______________Use of @ in Decorators __________ We simply use @ symbol before the function we would like to decorate. Example : def smart_div(func): def inner_div(a,b): if a
First learn what the following mean: 1.Python Closures 2.Python functions are first class objects This is not a tricky method nor does it have anything to do with decorator design patterns.
Div can also be called as the method you told, but if we want any function to be decorated by passing to any decorator then, we need to define a inner function which represents the function object of the decorated function. Hope you understand it well.
I urge you to please explain the flow of the function. I find it really hard to understand it and due to this reason I was forced to write this comment. Your previous videos were very good. I learnt many things.
sir i really enjoyed learning python playlist, but sir, i'm totally form mechanical background and in some cases i can't understand the what is happening in the code and why it has been written and i have the dout in the decorators i.e. def div(a,b): print(a/b)
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!
The same I felt
The best is when he makes mistakes and you can see his reaction lol makes it more real
Me also for any video web cam is must
totally agree ..
Very very true...
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.
I had to watch another video that explains it to make me see that the way he explained it was also very good. I was just thrown off by the lack of the @ syntax.
I was waiting for the @ thing, or a part 2 of this too.
anyway this was a good video. Subscribed.
Same here 😒 went to another video. But this one is really good too!
Need the link for the other video, did not get this concept
what is this @ syntax all about, i dont know this can get any link
please
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.
Yep. That would describe me. But Telusko threw in some really good information here. So basically the decorator is redefining where the 'div' object is pointing to in memory right?
But I don't know how to use @syntax and why they use @wrap. It will be helpful if he do separate video on this
So I think I agree with what @ranjeethstudio2483 is getting at, insofar as while yes,
"The syntax is unimportant if you don't know what is happening behind the scenes."
1. because the video is trying to teach what a wrapper is, at the same time that it's trying to explain what a decorator is, the video is harder to follow.
2. because this video is trying to teach what a decorator is, he should teach what a decorator is in a traditional setting. I.e. "here's what a decorator will look like when you see it in code and how it works."
3. It's not unimportant if you actually want to use them in your code.
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
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 teaching.etc......
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!
Try code with harry for this one than jump to telusko you will get the Idea. No offence i am not comparing these two channels they both have their own taste our main intention is to grasp the concept
The best explanation I've seen so far. I'm a Python beginner (I work with Javascript).
Isn' this almost exactly like javascript's closures?
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.
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 TH-camrs failed to explain.
Sir you are simply awesome. To be honest whenever I stuck for any technical topic, I immediately search on TH-cam to check if there is any similar video posted by you. Your way of teaching is too good. Many thanks.
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!
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.
Sir i saw the whole ad so that you get the reward😊😀
🤣
just click the add and close it. It works on a cost per click. It won't do anything if you just watch the add.
@Dharmesh Rajan your mindset is what I call 'chutiya' mindset. Clearly, you were never taught to give back. Tutors like Navin Reddy are teaching for free and can't you even watch a 30s ad for him? Nobody is asking how to get rid of ads here. @mohit and @MD are talking about supporting the video creator by watching ads. Get lost with your tip that no-one asked for.
@Dharmesh Rajan Hey! Take it easy. I was only discouraging 'greedy mindset'. It's not just 5 minutes but 5000 hours of experience, pre and post processing that TH-camrs put into their videos. So the feeling of being morally obliged to give back should come from within. That's what I wanted to imply. No intention of hurting anyone.
I felt like you were publicising the use of vanced on a completely irrelevant and unnecessary thread. Glad that you deleted it. Peace ✌️ and happy learning :)
@Stick / tutorials Thanks mate
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.
Now I understand WHY I would use a decorator ... simply illustrated and simply understood. We all learn differently and this was concise.
I was confused in decorators, but this is the only video from which I really got my confusion cleared! Thanks man, Keep it up
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.
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)
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
from math import sqrt
def modify(func):
def inn(a):
return a*a
return inn
sq=modify(sqrt)
print(sq(25))
print(sqrt(25))
My assignment sir 😁😁😁
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.
Exactly my thought 🤲
Really helpful video for me and after a long time I have found a best teacher for guidance in programming .Thank u so much sir
Hello sir,
I would say your skills always astonish me .Basically I am from ECE background I am facing difficulties to understand these topics So I always used to feel low .but after watching your videos in no time I get motivated and inspired by the way you teach us.you are really doing great work.it means a lot for us.keep doing sir .thank you
Hello,
I want to pursue ECE because i have interest in electronics field.
Can you tell me that which coding language is most important for ECE students and if an ECE student wants a job in software company , then how can they join because they are not tought coding upto that much level which is required for software development.
Same here I am also from ECE background and this is the first language I am learning ... Thank you sir for teaching in such a way that the non it student also easily catch the concepts
Best decorator tutorial I have found from youtube. Thank you!
This is the best example I found to understand decorator...😀
Beautifully explained !! I was looking everywhere for a relevant real scenario to test the use of decorators..
def decorator(func):
def new_div(a, b):
if a < b: # 2/4
a, b = b, a # 4/2
return func(a, b)
return new_div
@decorator
def div(a, b):
print(a/b)
div(2, 4)
Nice video sir. Awesome as always. I tried using @ symbol above a function. Thank you for the awesome videos. Waiting for the new videos.
sorry broh...i am little confused at @
@@pallasreenivasulu4624hi, you have to use @ followed by the decorator function name which you are going to use to add the additional functionality. Then the normal function will get the functionalities of the decorator function. Hope you understand. @ is used to specify that it is a decorator function which is used to extend the functionality of a normal function, without adding the additional code. Thank you.
@@rangabharath4253 Thank you Ranga
I have been looking for decorators and explanation. It is possible that I might not be looking at the right place or with right keywords but not a single video explained it so u effortlessly as you did. Kudos.
This guy is a phenomenal teacher.
what a explanation, great sir, none of other can explain like you.
thank you for tutorials.
Your presence makes the video so much better✨️
The best explanation I've seen so far. Thanks a lot Sir
Sir, Thank U for making decorators so easy. I have watched many videos but did not understood anything. Thanku and a great respect from Kerala 😊😊
I'll advise you do videos on concepts such as first-class functions and closures; these would help to understand the concept of decorators better. Well done.
I was smiling while watching this video. This video is amazing.❤❤❤
This is the best and simple explanation of Decorators I ever seen, good job :)
smart alien !.. you taught me this in 7.32 mn where i was trying hard to learn this from other sources for the past few hours
Decorators are one of things added to the list of "Never Use Unless you Want to Ruin Your Program". Tread carefully.
Since nobody wants to " 'Ruin [their] Program' " can you elaborate on when and when you should not use them, in your opinion? Prehaps give some resources?
You could also do your operation by using a HOF that just receives a function as one of its arguments. No need to return another function. An example:
def division(a,b): return a/b
def subtraction(a, b): return a - b
def do_operation(operation, a, b):
return operation(a, b) if a > b else operation(b, a)
print(do_operation(division, 4, 12)) # 3.0
print(do_operation(division, 12, 4)) # 3.0
print(do_operation(subtraction, 4, 12)) # 8
print(do_operation(subtraction, 12, 4)) # 8
Thank you Sir, now I have understood it properly.
I was working on decorator topic and also saw 2-3 videos but was not satisfied by the logic. But your teaching made me understand the concept very easily. Thank you :)
How it's actually work can anyone say step by step how it's work ..?
def div(a,b):
if a
Really nice explanation. Well produced video. Thanks!
Well explained, thank you
Wao.. excellent explanation sir.... finally my confusion is clear!!
2:04, Our mom's reaction, when we don't do our housework in this corona time.
😂
Hello Sir thank you very much for explaining the topic. I have one question regarding how the value is passed . When the object div1 was created and then in div1(2,4) value was passed , the object div1 was an instance of the function smart_div () which was taking a function as argument only, hence how the object of smart_div which is div1 pass the value 2,4 and got accepted. It will be helpful if you clear my doubt
def smart_div(func):
def inner(a,b):
if a
Sir, I have one doubt.
Can't I do like the code mentioned below?
def div(a,b):
print (a/b)
return a/b
def inner(a,b, func):
if a
this definitely helped - thanks. Can't say I still understand it to the bone, will have to re-watch, experiment & fail to 'get' it
Sir why did we use ‘return inner’ in the end, I didn’t understand. Because ‘return func(a,b)’ is already doing the work of calling div(a,b) right? Then what is the use of return inner?
If u don't understand, try watching it again.
It just worked for me,
Try watchin' it again and again till u get it.
Great teaching. But you missed @ syntax. and also can you explain it little deep about why we need to use inner functions etc. I am sure we can't explain decorator concept in just 7mins.
Really you have great teaching skill sir.... Thanks for explaining decorators🙏
Nice explanation sir :) , by the way, I think we can add '@' also right for using decorators instead of assigning the old function to the new one🤔
how does inner get called and when? what i have understood is we are passing the div function as parameter to the decorator function, which is returning inner_function. Now, the inner_function object or address will be overridden in the ‘div’ because we are capturing the returned function in it. After this, whenever we call div, the execution goes to inner_function in the decorator.
Bro I want to know about generators and Itreators so please have these two in your next video 🙏🙏
Amazing explanation..sir...thank you thank you so much
The way you teach sir is really very very smart😎
Hi. If the inner(a,b) function is the one that is responsible to add/modify/influence the code of div(a,b) function, then what is the need to write the inner(a,b) function within smart_div(func) function ?
What a fantastic explanation bro
omg !!! No one can explain decorators better than this
For people saying missing @ in the tutorial, please find the equivalent usage done by the tutor. You could either go with
div=smart_div(div) or use @ like @smart_div on top of function div. Both are same
U are a exellent mentor really awesome explanation and very very interesting the way u explained
Mathematically speaking, decorators make sense. its essentially the concept of two functions, function f, and function g, in which the output of function f is the input of function g, which can be expressed as g(f(x)). The value of f(x) is first computed and then is used as an input for the g function, which further acts on that output, thus "decorating" it. The concept is really simple, one function taking the output of another function as its input. The confusion arises because of Python's mapping, and syntax, which quite honestly, takes a while to "register".
So based on the example in this video, for instance, it supposed there is a function called div, which takes two arguments, a and b, and divides a by b, such as:
a = int(input("Enter a value for a: ")
b = int(input("Enter a value for b: ")
def div(a, b):
print(a/b)
Then the function is called:
div(a, b).
If the user entered a value to "a", that is less than the value entered to "b", it will result in an output less than 1, and will violate the question.
The way this problem can be solved, evidently, is through the use of decorators, which essentially declares a new function, such as div_new that takes the original div function as its input, and makes the necessary adjustments, such as reversing the value of a and b, or computing b/a, so that regardless of if the input value of a < b, the result will yield an integer value greater or equal to 1. Mathematically, the Python code would look like this:
[code]
def new_div(div(a, b)):
def div(a, b):
print(a/b)
if a < b:
print(b/a)
new_div(div(a, b))
[/code]
Basically, a new function new_div is created that takes the original first function div as its input. Once it goes inside the body of new_div, keeping in mind the values a, and b obtained by the client, it encounters the div function, which performs operations on a, b. Then it exits out of that function and falls into the body of new_div, encountering an if statement that tests the validity of a < b, and if it's True, then it instead prints out b/a, the reverse of a/b, which computes the quotient to a value greater than or equal to 1, without modifying the first function, thus solving the question correctly.
This is the logic, though if you try to run that code the way it's written, python will throw all kinds of errors. lol. But for those trying to understand the logic, hope this helps.
At 6:25 how does the inner function get the parameters of div? How are a and b given into this construct??
so confusing
This could be the possible decorator systex
def smart_div(func):
def inner(a, b):
if(a
2:04 - When a junior dev asks for help from a senior dev
Sir, my name is Krishnan.I am studying eleventh(11) standard . I have doubt whether this course is applicable for me. Kindly reply sir. Great teaching. I have doubt whether my school will teach like you and all the syllabus taught by you. I wanted to use the time judiciously during this corona time
yes !!!! this is helpful for all 11th and 12th grads to learn in advance
# use of decorator in divison both way
def div(a,b):
print(a/b)
def smart_div(func):
def inner(a,b):
if a
your teaching style tooooooooooooo impressive
I did n't see anyone like your exaplantion your amazing i got clear idea about this
def div(a,b):
print(a/b)
def inner(a,b):
if a
Thank you very much. You are a genius.
Sir learnt a lot of Python from your videos... But sir when you were discussing about OOPs concept.. You used the words Abstraction and Encapsulation which you never explained.. A request to you sir. Please make a video on that too..
abstraction stand for abstracting the data or hide the main code of function and show the neseccary detail to user like we are using ac remote,we press the on/off button but we don't know the concept of behind this pressing button this is called abstraction,or encapsulation stands for encapsulate the method/function or variable/variables in the class together is called encapsulation
def div(a,b):
return (a/b)
print("step1") # step 1:'div' function will be called
print(div(1,3))
print("step2") # step 2: 'div' function called and execution complete
# (Step 1 & 2 has nothing to do with decorator_function)
def decorator_function(func):
print("step4") # step 4: 'decorator_function' execution starts. Note that 'inner_function' is still not called
def inner_function(a,b):
print("step7") # step 7: 'div1' function which is replica of 'inner_function' is being executed
if a
Can we modify the in-built functions using decorators?
Sir when we defineing the function we must be call the function that's why the function it's works.but the inner function we don't calling how it's works?
@Telusko : I did not understand the use case of this decorator here , can't we just wrap div() in side another function which will just swap the values and pass to div() ?
def div(x, y):
print(x/y)
def smart_div(x,y ):
if x
Maybe new arguments of div method will also swap. but not sure
Nice teaching ....evryone can't b a teacher...
orrr you could just write this simple lambda expression:
smartDiv = lambda a, b : a/b if a > b else b/a
Lambda can have only 1 expression I suppose dude
I really appreciate this. You simplified this topic well
def div(a,b):
if a>b:
print(a/b)
else:
print(b/a)
div (2,8)
# add functionality to div() without altering div()
def smart_div(function):
def inner(x, y):
if x < y:
x, y = y, x
if y == 0:
print("y cant be zero")
return
function(x, y) # calling div with new values
# return function(x, y)
return inner
@smart_div # dec
def div(a, b):
print(a/b)
# use '@' or 'div = smart_div(div)
'
div(2, 4)
hello mr Navin, at last i found your channel about decorator.
thanks a lot sir!!!
God Bless
Before calling the function, what if I swap numbers (let's say prompted from user) checking inside if loop? Correct me if I am wrong.
same thing w/o this stuff:
def smart_div(a, b):
if a < b:
a, b = b, a
return div(a, b)
you are new tesla
you are doing a great effort naveen sir . the like to dislike ratio is very low only in this channel.i will put like then only wathching vedio
Can you guys help me understand something; If the below code also works (ignoring the ZeroDivision Error) why is there a need to add the additional inner function, as is in the tutorial?
def div(a,b):
print(a/b)
def smartDiv(a,b):
if a
______________Use of @ in Decorators __________
We simply use @ symbol before the function we would like to decorate.
Example :
def smart_div(func):
def inner_div(a,b):
if a
sir i didnt understand y should we write a another inner function in the new one.
cant we pass the inputs of div directly to smart div
no u cannot pass thats why we are using little bit tricky method
You can read more about decorator design pattern. That will clear as why we can't pass the values directly.
First learn what the following mean:
1.Python Closures
2.Python functions are first class objects
This is not a tricky method nor does it have anything to do with decorator design patterns.
Div can also be called as the method you told, but if we want any function to be decorated by passing to any decorator then, we need to define a inner function which represents the function object of the decorated function.
Hope you understand it well.
Your videos are always helpful, sir can u make some more examples for decorators? so we can get more clear idea of decorators.
Most coding teachers cannot explain anything. You can. This made sense.
Sir thanks for the lecture literally u are doing a great job...!!!!
Can we do the same thing without using the inner function there ,so that we just make use of smart_ div function directly
Sir could u please make one separate video on decorator elaborately
I urge you to please explain the flow of the function. I find it really hard to understand it and due to this reason I was forced to write this comment. Your previous videos were very good. I learnt many things.
sir i really enjoyed learning python playlist, but sir, i'm totally form mechanical background and in some cases i can't understand the what is happening in the code and why it has been written and i have the dout in the decorators i.e.
def div(a,b):
print(a/b)
def smart_div(func):
def inner(a,b):
if a
Thank you sir I understood this concept.
So what i got from that is that decarators are functions that help with changing other function without messing with them right?