#44 Python Tutorial for Beginners | Decorators

Поділитися
Вставка
  • Опубліковано 28 лип 2024
  • Check out our courses:
    Spring and Microservices Weekend Live Batch : bit.ly/spring-live-weekend
    Coupon: TELUSKO10 (10% Discount)
    Master Java Spring Development : bit.ly/java-spring-cloud
    For More Queries WhatsApp or Call on : +919008963671
    website : courses.telusko.com/
    Instagram : / navinreddyofficial
    Linkedin : / navinreddy20
    TELUSKO Android App : bit.ly/TeluskoApp
    Discord : / discord
    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.
    Github :- github.com/navinreddy20/Python-
  • Наука та технологія

КОМЕНТАРІ • 455

  • @bharathg7284
    @bharathg7284 5 років тому +555

    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!

    • @wolverine87833
      @wolverine87833 4 роки тому +3

      The same I felt

    • @Dre2k07
      @Dre2k07 4 роки тому +17

      The best is when he makes mistakes and you can see his reaction lol makes it more real

    • @_.sunnyraj._
      @_.sunnyraj._ 4 роки тому +1

      Me also for any video web cam is must

    • @iamniks
      @iamniks 4 роки тому +2

      totally agree ..

    • @shivaramakrishnans4880
      @shivaramakrishnans4880 4 роки тому +2

      Very very true...

  • @chrism3790
    @chrism3790 5 років тому +227

    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.

    • @HomerSimpsonian
      @HomerSimpsonian 5 років тому +15

      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.

    • @bakachelera
      @bakachelera 4 роки тому +10

      I was waiting for the @ thing, or a part 2 of this too.
      anyway this was a good video. Subscribed.

    • @gayalkuruppu9387
      @gayalkuruppu9387 4 роки тому +2

      Same here 😒 went to another video. But this one is really good too!

    • @obviouscreed
      @obviouscreed 4 роки тому +5

      Need the link for the other video, did not get this concept

    • @ritamchatterjee3307
      @ritamchatterjee3307 3 роки тому +1

      what is this @ syntax all about, i dont know this can get any link
      please

  • @kamilkurzynowski3836
    @kamilkurzynowski3836 3 роки тому +35

    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.

    • @purplemonkeydishwasher5269
      @purplemonkeydishwasher5269 2 роки тому

      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?

    • @ranjeethstudio2483
      @ranjeethstudio2483 5 днів тому

      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

  • @kandasamymurugadas6838
    @kandasamymurugadas6838 4 роки тому +25

    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

  • @GiovaniGalicia
    @GiovaniGalicia 5 років тому +71

    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!

    • @akashsuna5160
      @akashsuna5160 2 роки тому

      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

    • @SpaceTimeBeing_
      @SpaceTimeBeing_ 2 роки тому

      @@akashsuna5160 don't promote that guy. India was humiliated 2 years ago during github's hacktoberfest because this moron misguided clueless people into participating in it. It was horrible thanks to him.

  • @tarunseetha
    @tarunseetha 5 років тому +5

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

  • @liveinthemoment6218
    @liveinthemoment6218 Рік тому +5

    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......

  • @kruthikahu904
    @kruthikahu904 4 роки тому +8

    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.

  • @asishraz6173
    @asishraz6173 4 роки тому +6

    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 UA-camrs failed to explain.

  • @ZyroZoro
    @ZyroZoro 5 років тому +17

    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.

  • @mdsadaquathussain307
    @mdsadaquathussain307 5 років тому +89

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

    • @_.sunnyraj._
      @_.sunnyraj._ 4 роки тому +2

      🤣

    • @mohitbendale8229
      @mohitbendale8229 4 роки тому +9

      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.

    • @SaFFire123x
      @SaFFire123x 3 роки тому +2

      @@063dharmeshrajan5 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.

    • @063dharmeshrajan5
      @063dharmeshrajan5 3 роки тому +1

      @@SaFFire123x Sorry man , I'll predicted above 1 comment wrong I am deleted my above comment but my prediction is not to hurt someone just help for those whose study continuosly and got so much irritated from ads and for your sake I am watching all (studying)videos only on UA-cam version not Vanced version I know that it affects the earning but I know how and when do we use vanced version and please don't abused any one else again this show which type of background you come from okay I am ☮️ peacefully Sorry but do not use abusive language.

    • @SaFFire123x
      @SaFFire123x 3 роки тому +2

      @@063dharmeshrajan5 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 UA-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 :)

  • @hariomjoshi7131
    @hariomjoshi7131 2 роки тому +6

    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.

  • @kavnainvohra8228
    @kavnainvohra8228 3 роки тому +3

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

  • @extraxt
    @extraxt 5 років тому +12

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

  • @varungrow6036
    @varungrow6036 4 роки тому +2

    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

  • @nileshmishra8656
    @nileshmishra8656 3 роки тому +2

    Beautifully explained !! I was looking everywhere for a relevant real scenario to test the use of decorators..

  • @viswanath514
    @viswanath514 3 роки тому +1

    This is the best and simple explanation of Decorators I ever seen, good job :)

  • @akashdeep7519
    @akashdeep7519 4 роки тому +2

    what a explanation, great sir, none of other can explain like you.
    thank you for tutorials.

  • @mikekibet1786
    @mikekibet1786 5 років тому +10

    Well explained, thank you

  • @subomifatoyinbo4322
    @subomifatoyinbo4322 3 роки тому +2

    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.

  • @JasonGabler
    @JasonGabler 2 роки тому +1

    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.

  • @sreekalapm2588
    @sreekalapm2588 4 роки тому +1

    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

  • @asb8035
    @asb8035 2 роки тому +2

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

  • @TheKapilsharma143
    @TheKapilsharma143 3 роки тому +10

    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.

    • @feagy
      @feagy 2 роки тому

      Exactly my thought 🤲

  • @faiyaz7697
    @faiyaz7697 4 роки тому +2

    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 ?

  • @sudheerpapasani541
    @sudheerpapasani541 5 років тому +9

    Bro I want to know about generators and Itreators so please have these two in your next video 🙏🙏

  • @aishwaryalaxmiveeramalla739
    @aishwaryalaxmiveeramalla739 4 роки тому +1

    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)

  • @lokesh007bondcool
    @lokesh007bondcool 4 роки тому +1

    Sir thanks for the lecture literally u are doing a great job...!!!!

  • @samthejam5202
    @samthejam5202 4 роки тому +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

  • @UmaMaheshBandii
    @UmaMaheshBandii 4 роки тому +1

    I did n't see anyone like your exaplantion your amazing i got clear idea about this

  • @Aavikko12
    @Aavikko12 5 років тому +6

    Best decorator tutorial I have found from youtube. Thank you!

  • @samiamuhammad8140
    @samiamuhammad8140 4 роки тому +2

    That is the best explanation. Thanks

  • @divyasinha8204
    @divyasinha8204 3 роки тому +1

    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?

  • @hughp5646
    @hughp5646 3 роки тому +1

    Really nice explanation. Well produced video. Thanks!

  • @Nnirvana
    @Nnirvana 4 роки тому +1

    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.

  • @usmanafzal9377
    @usmanafzal9377 5 років тому +1

    Sir How can we call a function which is defined below in the function that is defined above it?

  • @asishraz6173
    @asishraz6173 4 роки тому +13

    2:04, Our mom's reaction, when we don't do our housework in this corona time.

  • @sanjitpaul2953
    @sanjitpaul2953 3 роки тому +1

    Thank you Sir, now I have understood it properly.

  • @navaneethjnair6903
    @navaneethjnair6903 2 роки тому

    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 😊😊

  • @ayushsingh1726
    @ayushsingh1726 4 роки тому +2

    Sir please make another video explaining this . Please sir .

  • @prince43917
    @prince43917 4 роки тому +2

    Thankyou sir its really helpful .

  • @gpsnavi
    @gpsnavi 4 роки тому

    How can we make the inner function global to use else where when setting up other decorators?
    Can this be achieved?

  • @abaskisekka5137
    @abaskisekka5137 4 роки тому

    i like this guy, he is so audible and straight on point

  • @iamniks
    @iamniks 4 роки тому +1

    sir i have question.
    what if we use extend of div class to create another class so that, we can use div class properties is this possible?
    please tell me

  • @taufeequesifat8120
    @taufeequesifat8120 3 роки тому +8

    2:04 - When a junior dev asks for help from a senior dev

  • @letstry2854
    @letstry2854 3 роки тому +1

    Wao.. excellent explanation sir.... finally my confusion is clear!!

  • @gokulkrishnanselvaraj2384
    @gokulkrishnanselvaraj2384 3 роки тому +1

    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?

  • @debjyotibanerjee7750
    @debjyotibanerjee7750 3 роки тому +1

    This is the best example I found to understand decorator...😀

  • @06_shubhambirhade81
    @06_shubhambirhade81 3 роки тому +1

    Your videos are always helpful, sir can u make some more examples for decorators? so we can get more clear idea of decorators.

  • @MohammadIsmailAkheel
    @MohammadIsmailAkheel 2 роки тому +1

    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.

  • @ericwilson2295
    @ericwilson2295 4 роки тому

    this helped me understand better. thanks very much

  • @iamdeepika2219
    @iamdeepika2219 3 роки тому +3

    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

    • @amansinghal349
      @amansinghal349 3 роки тому

      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.

    • @dipikapandya3163
      @dipikapandya3163 3 роки тому

      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

  • @sachetambere7028
    @sachetambere7028 4 роки тому +1

    hello sir,
    The changes which we are making in the existing function are permanent or temporary ???

  • @meetangad
    @meetangad 4 роки тому +1

    Sir - Can you advise what is the purpose of return used within smart div and inner?

  • @vaibhavkrkm
    @vaibhavkrkm 4 роки тому +3

    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🤔

  • @0806nidhi
    @0806nidhi 4 роки тому

    Thank you for the explaination :)

  • @syedashaguftaafshan4019
    @syedashaguftaafshan4019 2 роки тому

    I have two functions which is used for serial com and other is ssh which is used to connect to target ...How to develop wrapper combining these two

  • @user-db4wu8lq7n
    @user-db4wu8lq7n 6 місяців тому

    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.

  • @anishdey3507
    @anishdey3507 4 роки тому +3

    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

  • @amulingle
    @amulingle 4 роки тому

    When we had Simple prgram initial with less number of linnes of prgam then why we should go with max lines in 2nd phase which decorators mode

  • @pallasreenivasulu4624
    @pallasreenivasulu4624 5 років тому +1

    hi navin..i got the concept what you have given but i am totally confused while practicing

  • @nileshpendorkar8599
    @nileshpendorkar8599 2 роки тому

    Really you have great teaching skill sir.... Thanks for explaining decorators🙏

  • @GopalSharma-mf1gd
    @GopalSharma-mf1gd 5 років тому

    is new div permanently changed ?? what if I use put (4,2) now

  • @bsmaheshkumar5328
    @bsmaheshkumar5328 4 роки тому +1

    Why do we have to write the logic inside the function of smart_div()?
    We could have done that right after smart_div function isn't it?
    Can anyone, please explain to me about this?

  • @adarshpaliwal4715
    @adarshpaliwal4715 5 років тому +1

    The way you teach sir is really very very smart😎

  • @saicharan4669
    @saicharan4669 4 роки тому +1

    Can we do the same thing without using the inner function there ,so that we just make use of smart_ div function directly

  • @swamygoskula1785
    @swamygoskula1785 3 роки тому +1

    U are a exellent mentor really awesome explanation and very very interesting the way u explained

  • @radhakrishnankv3903
    @radhakrishnankv3903 4 роки тому

    In the above program, if we changed the values like div(4,2), it will not be returned output:(
    ie. div function is not getting called.

  • @rvstech8435
    @rvstech8435 2 роки тому

    we are passing func as input parameter of the fucnction how could that be working can you expalin in deatil

  • @parthasarathihazra9330
    @parthasarathihazra9330 2 роки тому

    suppose the div() function was in a different file after importing it to a new file and changing using decorator......so will the div() in the original file change??

  • @koushikchhetri8883
    @koushikchhetri8883 4 роки тому +1

    This could be the possible decorator systex
    def smart_div(func):
    def inner(a, b):
    if(a

  • @yfjsdgzjdnfn
    @yfjsdgzjdnfn Рік тому +1

    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 😁😁😁

  • @sr-ju4lq
    @sr-ju4lq 2 роки тому

    Your presence makes the video so much better✨️

  • @praveerroshan8376
    @praveerroshan8376 3 роки тому +2

    @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

    • @anilrautela5260
      @anilrautela5260 2 роки тому

      Maybe new arguments of div method will also swap. but not sure

  • @dhonidinesh5707
    @dhonidinesh5707 5 років тому

    Hi Navin,I have decide to learn the UI Path,please tell me how is about UI path Scope in India

  • @shubhajitchakraborty
    @shubhajitchakraborty Рік тому +1

    This guy is a phenomenal teacher.

  • @gopakumars1701
    @gopakumars1701 3 роки тому +1

    could you please create a detailed video on decorators for clarrification?

  • @sanusiabubakr1948
    @sanusiabubakr1948 9 місяців тому

    I really appreciate this. You simplified this topic well

  • @muggullasairam8442
    @muggullasairam8442 2 роки тому +1

    Amazing explanation..sir...thank you thank you so much

  • @amalkrishnas1696
    @amalkrishnas1696 Рік тому

    very helpful, thanks for the video

  • @edwardgregory9219
    @edwardgregory9219 4 роки тому +1

    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

  • @mayankjulah4408
    @mayankjulah4408 4 роки тому +1

    Can we modify the in-built functions using decorators?

  • @raihanation
    @raihanation 4 роки тому

    you are amazing sir, thanks a lot

  • @MohitKumar-ri3yv
    @MohitKumar-ri3yv 3 роки тому

    omg !!! No one can explain decorators better than this

  • @saurabhruikar1131
    @saurabhruikar1131 2 роки тому

    Can anyone explain how inner function is getting arguments a and b, when smart function calls inner, it is not passing any arguments.

  • @Aerish369
    @Aerish369 Рік тому

    Thank you sir I understood this concept.

  • @snehalsalve6799
    @snehalsalve6799 Рік тому

    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 :)

    • @user-sr4ul5xx3o
      @user-sr4ul5xx3o Рік тому

      How it's actually work can anyone say step by step how it's work ..?

  • @Alphabetbubi
    @Alphabetbubi 5 років тому +7

    At 6:25 how does the inner function get the parameters of div? How are a and b given into this construct??

  • @SreekanthReddy22
    @SreekanthReddy22 3 роки тому +1

    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

  • @Pavankumar-xl4ov
    @Pavankumar-xl4ov 3 роки тому +2

    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.

  • @techy-anirban4067
    @techy-anirban4067 4 роки тому +1

    Sir could u please make one separate video on decorator elaborately

  • @vakhariyajay2224
    @vakhariyajay2224 2 роки тому +1

    Thank you very much. You are a genius.

  • @karthikp7518
    @karthikp7518 5 років тому +9

    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

    • @deepakkumarsharma3694
      @deepakkumarsharma3694 5 років тому

      no u cannot pass thats why we are using little bit tricky method

    • @RahulSingh-up8jo
      @RahulSingh-up8jo 5 років тому

      You can read more about decorator design pattern. That will clear as why we can't pass the values directly.

    • @jaystore2596
      @jaystore2596 4 роки тому

      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.

    • @souvikghosh6966
      @souvikghosh6966 4 роки тому

      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.

  • @atulsoni9712
    @atulsoni9712 3 роки тому

    creating another function inner is necessary? can we not apply the condition inside the body of smart_div only?

  • @BT-te9vx
    @BT-te9vx Рік тому

    this definitely helped - thanks. Can't say I still understand it to the bone, will have to re-watch, experiment & fail to 'get' it

  • @ganeshronge3449
    @ganeshronge3449 Рік тому +1

    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

  • @stefkoum8111
    @stefkoum8111 Рік тому

    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

  • @timtech9361
    @timtech9361 2 роки тому +2

    Decorators are one of things added to the list of "Never Use Unless you Want to Ruin Your Program". Tread carefully.

  • @dilhaishaayr6142
    @dilhaishaayr6142 4 роки тому

    Thanks sir you have a good skills

  • @orazovdidar
    @orazovdidar 3 місяці тому

    Thank you Telusko, it helped