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

Комментарии • 140

  • @nishchalchandrajwar4885
    @nishchalchandrajwar4885 5 лет назад +16

    Best python lectures in RUclips.... You nailed it.. Thankuu...

  • @aparajitakumari2936
    @aparajitakumari2936 2 года назад

    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.

  • @sunnyjain630
    @sunnyjain630 Год назад

    Finally I got the concepts of Decorators. Thanks❤️

  • @TheJeromeDominic
    @TheJeromeDominic 4 года назад +8

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

  • @jagadeeshbusani606
    @jagadeeshbusani606 5 лет назад +1

    Great video on decorator. Looking forward for more like this!!! Thanks.

  • @haribhaskar72
    @haribhaskar72 2 месяца назад

    Thanks for this Video, you explained decorator function very well. God bless you...

  • @akankshavijayvergiya1431
    @akankshavijayvergiya1431 5 лет назад +2

    this is probably the best video .explained in detailed manner

  • @naveenkumarkaranam3612
    @naveenkumarkaranam3612 Год назад

    Your teaching is simply super

  • @shikhaverma8375
    @shikhaverma8375 2 года назад

    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

  • @richluetoure3683
    @richluetoure3683 4 года назад +1

    Amuls is the best.

  • @satyajitdas2780
    @satyajitdas2780 5 лет назад +6

    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

    • @AmulsAcademy
      @AmulsAcademy  5 лет назад

      Thank you :)
      I will upload it soon :)

  • @anuradhakumari6123
    @anuradhakumari6123 2 года назад

    Thanks a lot. Very well explained thr concept

  • @mayuridas5161
    @mayuridas5161 4 года назад +2

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

  • @Prajwal_KV
    @Prajwal_KV 3 года назад +1

    Amulya Thanks a lot .After watching a ample videos from other youtube channels finally your video cleared the concepts vividly.

  • @sowndharya183
    @sowndharya183 5 лет назад +2

    Explaining clearly and easy to understand.. Superbb

  • @taiwanSmart
    @taiwanSmart 4 года назад +1

    you are so intelligent, not only good at coding, but also good at teaching, thank you!

  • @ankitgupta-wz3oj
    @ankitgupta-wz3oj 2 года назад

    Very helpful session. Thanks a lot

  • @vijayaramaraju2856
    @vijayaramaraju2856 2 года назад

    Your explanation is really good

  • @sathishdarshanala6137
    @sathishdarshanala6137 3 года назад +1

    amulya thnks for explaining decorators u r the best teacher

  • @umaranjan4481
    @umaranjan4481 3 года назад +1

    Better than any python tutorial on you tube....

  • @souravdeb3613
    @souravdeb3613 4 года назад +2

    excellent..consolidated each and every concept in a single space..request to continue making videos on different topics in python

  • @philipberthiaume2314
    @philipberthiaume2314 2 года назад

    Brilliant, thank you...

  • @Snake_Fire0
    @Snake_Fire0 3 года назад +1

    You are the Best teacher.

  • @rajeshvenkatsubbu5350
    @rajeshvenkatsubbu5350 3 года назад +1

    the way you explained is really awesome...

  • @sanketsuryawanshi
    @sanketsuryawanshi 3 года назад +1

    Great Explanation Ever I Seen !! 👍🔥

  • @kartikchakraborty5511
    @kartikchakraborty5511 5 лет назад +2

    Very helpful
    .. thanks you..

  • @PRADEEP_SUNKARI
    @PRADEEP_SUNKARI 5 лет назад +7

    Hi Amulya .I am new subscriber to ur channel.your explanation is very good .

  • @natsudragneel8305
    @natsudragneel8305 4 года назад +2

    best tutorial for decorator

  • @shruthik7278
    @shruthik7278 2 года назад

    Too good mam thank you so much

  • @natsudragneel8305
    @natsudragneel8305 4 года назад +2

    Thankyou so much

  • @sardarahmed5174
    @sardarahmed5174 5 лет назад +2

    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

    • @AmulsAcademy
      @AmulsAcademy  5 лет назад +2

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

  • @sivasankar7195
    @sivasankar7195 5 лет назад

    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

  • @rajeshh2792
    @rajeshh2792 3 года назад +1

    Good Tutorial Amulya.

  • @sureshreddy3773
    @sureshreddy3773 3 года назад +1

    Big fan of ur content and voice ❤️

  • @sankethb.k642
    @sankethb.k642 5 лет назад

    Thanks a lot mam

  • @balakrishnavaidyanathan8572
    @balakrishnavaidyanathan8572 3 года назад +1

    Amulya's academy python videos are best.i really appreciate your videos

  • @harik1999
    @harik1999 5 лет назад +1

    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 ?

    • @AmulsAcademy
      @AmulsAcademy  5 лет назад

      Thank you :)
      Sure i will make deep and shallow copy videos asap :)

  • @prasadpathak3209
    @prasadpathak3209 4 года назад

    Hey Amulya what about if I have multiple nested functions what should it work

  • @waleedislam3280
    @waleedislam3280 4 года назад +1

    EXCELLENT

  • @noblessetech
    @noblessetech 4 года назад +3

    your voice is very pleasing to ear..!

  • @chetanmazumder310
    @chetanmazumder310 3 года назад +1

    Mam , you are awesome !!!

  • @venkatraj608
    @venkatraj608 3 года назад +1

    Madam very nice explanation and pronouns I search your Chanel bottom of line good keep top

  • @SapnaGupta-vv5fr
    @SapnaGupta-vv5fr 5 лет назад +1

    satisying explanation
    like it

  • @DaniruDEV
    @DaniruDEV 3 года назад +1

    I stucked at decorators thanks for changing it

  • @himabindugandikota4526
    @himabindugandikota4526 4 года назад

    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)

  • @bharatruttala7187
    @bharatruttala7187 2 года назад

    Thanks a lottttttt

  • @drsmahesan203
    @drsmahesan203 3 года назад

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

  • @taran1985
    @taran1985 Год назад

    17:38, how did the function inner (x, y) was assign the value of div(a, b) , x=a, y=b.. ?

  • @janakiyeluripati6368
    @janakiyeluripati6368 4 года назад

    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?

  • @alinisar2553
    @alinisar2553 3 года назад

    what is the purpose of Nested function i.e (inner()) inside the decorator function?

  • @entirebentirec3296
    @entirebentirec3296 4 года назад +1

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

    • @drsmahesan203
      @drsmahesan203 3 года назад

      Yes, but setting decorator is equivalent to redefining div as div = decor_div(div)

  • @globalgrowth343
    @globalgrowth343 Год назад

    Thanks,
    But I like the way you say "now"

  • @meralmaradia4774
    @meralmaradia4774 3 года назад +1

    Great !! You deserve more subscribers (y)

    • @AmulsAcademy
      @AmulsAcademy  3 года назад

      Thank you 😊

    • @drsmahesan203
      @drsmahesan203 3 года назад

      If she appears once in a while, it may happen :-))

  • @bharatm9727
    @bharatm9727 4 года назад +1

    Can you start python - selenium

  • @ibrahimali-xd3bw
    @ibrahimali-xd3bw 3 года назад +1

    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.

    • @AmulsAcademy
      @AmulsAcademy  3 года назад

      Give me the program please :)

    • @ibrahimali-xd3bw
      @ibrahimali-xd3bw 3 года назад

      @@AmulsAcademy working fine now , but I don't know what happened!!!
      Thanks

    • @AmulsAcademy
      @AmulsAcademy  3 года назад

      Ok :)

  • @bunnyvlogs7647
    @bunnyvlogs7647 3 года назад +1

    hi mam....best explanation...................... can u help on same with singleton class from scratch

  • @jchakrab
    @jchakrab 3 года назад

    why can't outer itself return str1.upper()..why inner is needed ? can u please explain...

  • @asurya
    @asurya 4 года назад +1

    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

    • @amitunemelody5612
      @amitunemelody5612 4 года назад +1

      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

    • @drsmahesan203
      @drsmahesan203 3 года назад

      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.

  • @BS-eu9do
    @BS-eu9do 4 года назад +4

    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

    • @vidyasagarreddy3668
      @vidyasagarreddy3668 3 года назад

      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

    • @smenezes5359
      @smenezes5359 3 года назад

      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]

  • @vikaskale5640
    @vikaskale5640 2 года назад

    Mam make more videos on python

  • @jagadeeshbusani606
    @jagadeeshbusani606 5 лет назад +1

    Can pls make a detailed video on Generators as well...

  • @sowndharya183
    @sowndharya183 5 лет назад +1

    New subscriber 😊

  • @tanujtiwari8581
    @tanujtiwari8581 2 года назад

    hii ,
    if we can change the lower case letters to upper with single function then why you use nested function in this case.

  • @entirebentirec3296
    @entirebentirec3296 4 года назад

    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)

  • @sujitdas5745
    @sujitdas5745 5 лет назад +1

    Your videos are very helpful for me.But now our college start "GNU octave" coding so can you help me?????

    • @AmulsAcademy
      @AmulsAcademy  5 лет назад

      Now i can't start sorry :)

    • @sujitdas5745
      @sujitdas5745 5 лет назад

      Please mention some books for GNU octave and Python...

  • @calliart6586
    @calliart6586 4 года назад

    Damn.. tricky

  • @debojitmandal8670
    @debojitmandal8670 3 года назад +1

    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

  • @amrithpurandhar9882
    @amrithpurandhar9882 2 года назад

    how are x,y related to a,b

  • @anuppradhan6876
    @anuppradhan6876 2 года назад

    if we want to modify a function later we can modify it later without using decorators also. Then why do we use decorators??

  • @shamanr897
    @shamanr897 4 года назад +4

    6:58 you can here a rooster crowing in the background (0_o)

  • @felipica
    @felipica Год назад

    ajudou mt mano slk valeu

  • @shaikbyte
    @shaikbyte 4 года назад

    may god give the understandable capacity, who disliked this video...

  • @pankajsingh6925
    @pankajsingh6925 2 года назад +1

    Hello ma'am, if you have any full fledge python project as a paid course do let me know...

  • @mohitdhiman7230
    @mohitdhiman7230 4 года назад +1

    in first example you return the inner function first after that return strupdate,but in second example you return inner function in last.why?

    • @AmulsAcademy
      @AmulsAcademy  4 года назад

      Give me the video timing please :)

    • @mohitdhiman7230
      @mohitdhiman7230 4 года назад +1

      @@AmulsAcademy 6:42 and 13:57

    • @AmulsAcademy
      @AmulsAcademy  4 года назад +1

      In both example i returned inner at last.
      :)

    • @mohitdhiman7230
      @mohitdhiman7230 4 года назад

      @@AmulsAcademy 😁got it..... thnx

  • @kkmahapatra8538
    @kkmahapatra8538 4 года назад

    I can't get it properly........

  • @sayanjitb
    @sayanjitb 3 года назад

    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?

    • @sayanjitb
      @sayanjitb 3 года назад

      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

  • @omenechris4698
    @omenechris4698 2 года назад

    Jesus!
    Woman I bow!

  • @srikarveeravatnam3267
    @srikarveeravatnam3267 Год назад

    GOOD at explaining ....by the way i didin't receive any watch😉

  • @zizo8737
    @zizo8737 5 лет назад +2

    I can’t understand 😭

  • @soham19902008
    @soham19902008 4 года назад +1

    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

    • @AmulsAcademy
      @AmulsAcademy  4 года назад +1

      Thank you :)
      amulsacademy@gmail.com
      you can ask your queries in our fb page also.
      :)

  •  4 года назад

    lots of "OKEY?" ma'm...

  • @munivoltarc
    @munivoltarc 7 месяцев назад

    don't use repeatedly the word 'right' okay, it is not impressive in your explanation

  • @janakiyeluripati6368
    @janakiyeluripati6368 4 года назад

    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?