Python Decorators in 15 Minutes

Sdílet
Vložit
  • čas přidán 15. 05. 2024
  • Decorators are an advanced feature of the Python language that allow you to modify the behavior of a function or method without touching its code. This video will teach you why decorators work and how to create your own. It will also walk through a few examples to give you a better idea of where to use Python decorators.
    ⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. We made this CZcams channel and Kite to help you be more productive: kite.com/download/?...
  • Věda a technologie

Komentáře • 434

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 Před 3 lety +351

    Just to recap:
    * Every value in Python is an object.
    * Functions and classes are objects.
    * Function definitions and class definitions are best thought of as special kinds of assignment statements, not as declarations; there are no declarations as such in Python.
    Decorators work with classes as well, not just functions. Also worth adding:
    * Every object is an instance of a class.
    Note this also applies to classes, since they are objects.

    • @theobellash6440
      @theobellash6440 Před 3 lety +6

      Python Fonctions and Classes are C classes... Python is an alphabet soup of C classes and objets and slowly interpreted🍝 spaghetti codes but somehow compréhensive

    • @riosdellacueva6482
      @riosdellacueva6482 Před 3 lety +2

      use yield

    • @Artaxerxes.
      @Artaxerxes. Před 2 lety +1

      It's just a function pointer lmao. You sound really naïve when you call everything an object

    • @arpit743
      @arpit743 Před 2 lety

      @@Artaxerxes. what's a function pointer

    • @vertigo390
      @vertigo390 Před 2 lety +2

      Every object is an instance of a class, even classes since they are objects.
      According to this statement, classes are objects, instances of a class which is itself an object, instance of a class which is also itself an object, instance of a class...
      You see where I'm going.
      What's the highest point? There must be a class that isn't an instance of a higher-order class, or it'll repeat infinitely.

  • @willemvdk4886
    @willemvdk4886 Před 3 lety +249

    I've read about decorators a dozen times. In books, tutorials, documentation of frameworks, etc. This is honestly the first time I actually understand the concept. Best explenation ever. Thanks Tim!

  • @SumanPokhrel0
    @SumanPokhrel0 Před 3 lety +145

    I looked so many videos, all of them were confusing. But this one just the perfect content I wanted. Thanks for this awesome video

    • @KiteHQ
      @KiteHQ  Před 3 lety +10

      So glad you found it helpful! Hope you are able to benefit from our other tutorials as well :)

    • @mranonymous7766
      @mranonymous7766 Před 2 lety +1

      @@KiteHQ Yeah i bought a python course still here watching your videos.

    • @ultimatejy9393
      @ultimatejy9393 Před 2 lety

      Agree!

    • @nicholasziglio
      @nicholasziglio Před 2 lety

      Same here! So well explained.

  • @mehregankbi
    @mehregankbi Před 3 lety +17

    the best ad for kites. have been seeing the ad everywhere but never wanted it. now i'm liking it

  • @RagingWhoremoans
    @RagingWhoremoans Před 3 lety +72

    Wow this Kite AI thingy is really advanced, it does a darn good impersonation of that Tim fellow.

    • @ultimatejy9393
      @ultimatejy9393 Před 2 lety

      So the man voice in this video is generated by AI with impersonating Tim??

  • @peetk5993
    @peetk5993 Před rokem

    I watched this video a year ago, created some decorator functions as snippets that I can use later. Now after a year I needed them so I used the snippets but honestly I forgot how they actually work but saved a link to your video. Watched this again and after 15 mins I understand everythingI need. I really appreciate your work Tim, I honestly think that there is absoutely nothing I could add or remove from your content like they go concisely from zero to a decent level of understanding in really short time.

  • @joekerr5418
    @joekerr5418 Před 4 lety +83

    hey, it's tech with tim!!

    • @furiousfellow1583
      @furiousfellow1583 Před 3 lety +9

      my first reaction at reading your comment was like, "duhh yes it is", then I read the channel name and was like WHAT??...

    • @damonchase1922
      @damonchase1922 Před 3 lety +1

      Kite sponsors his videos

  • @Dtomper
    @Dtomper Před 3 lety +12

    That log decorator is so powerful omg. Thank you for this amazing explanation

  • @garrenmiller9434
    @garrenmiller9434 Před 2 lety +17

    Great explanation. I really appreciated that you gave a few concrete examples where decorators are useful instead of cutting off after explaining the functionality.

  • @thomasdr08
    @thomasdr08 Před rokem

    Been trying to understand decorators, args, and kwargs for years. No clue how you were able to make this work so quickly and easily but I REALLY appreciate you!

  • @edwin5907
    @edwin5907 Před 3 lety +1

    This is what I wanted to see, someone who can explain Decorators in a easy and logic way..
    Thank you

  • @mikemace2860
    @mikemace2860 Před 8 měsíci +2

    Absolutely the best , most concise tutorial on decorators - thank you!

  • @jakeambrose4294
    @jakeambrose4294 Před 2 lety +1

    Explained and described on a deeper level that i would think we all want to grasp to truly understand how the codes are working. Great vid. This is my first finding of your vids, now ill be looking for the rest of your stuff. Greatly appreciate anyone who adds quality contributions to education.

  • @ShahinRzayevNergiz
    @ShahinRzayevNergiz Před 3 lety +3

    As of yet the best and readable explanation of the decorators in the net. Keep going, Tim, you do it best.

  • @naveenpemmana
    @naveenpemmana Před 4 lety +54

    I really loved the way you explained about the decorators. 😊

  • @Ayoutubeaccount3
    @Ayoutubeaccount3 Před 2 lety

    this is the first video I watched on the topic and understood it straight away, I think I was lucky as the other comments say they've read lots of documents and watched other videos without understanding it, but seriously dude your explanation and the way you speak makes it easy to follow along

  • @kristiantorres1080
    @kristiantorres1080 Před 3 lety +24

    The best explanation of decorators I've seen so far on youtube!

  • @SovsemNeProstoy
    @SovsemNeProstoy Před rokem +1

    When I saw function decorators first time I thoght that it's the easiest theme that I've ever seen, but then I understood how useful and complicated they are. And now, I can say that this tutorial gave me the concept of decorators.

  • @nonoobott8602
    @nonoobott8602 Před 6 měsíci

    This is by far the clearest and most intuitive explanation of the concept of decorators I've seen. Thanks for sharing

  • @orlanino
    @orlanino Před 3 lety +1

    Explanation of how to use it and inner working, business as usual. The explanation of when and why to use it, brilliant!

  • @rakeshankireddy7659
    @rakeshankireddy7659 Před 2 lety

    Perfect explanation. Looked at other articles and videos before but still had the confusion. This video taught the concept very clear.

  • @soyaleye
    @soyaleye Před 4 lety +1

    This is by far the most explanatory video for decorators I have seen on CZcams. It does not have the view count to match up to how helpful and insightful this video is.

  • @weneverforgetwearelegion

    took me a full day to grasp this, thanks.

  • @Sciencedoneright
    @Sciencedoneright Před 3 lety +77

    hey, it's Tech With Tim :O
    I was legit surprised

    • @denysivanov3364
      @denysivanov3364 Před 3 lety

      probably this guy copied tech with tim content....

    • @dl662
      @dl662 Před 3 lety +4

      This company has a shady history. They hijacked an autocomplete plug-in n defaulted users to upload their code to their servers in the backend. I ended up uninstalled autocomplete python n moved away from atom altogether. I bet they r pulling a similar trick here. So thanks but no thanks, I’m happy with Jedi n if I ever need an intelligent autocomplete tool I’ll build my own.

    • @jhonshephard921
      @jhonshephard921 Před 3 lety +2

      @@denysivanov3364 "this guy" is a kind-of well known code-completion company. Can be used as a plugin for VSCode.

    • @denysivanov3364
      @denysivanov3364 Před 3 lety +1

      @@jhonshephard921 I doubt that plugin copied Tech with Tim video =)

    • @emeraldthunder
      @emeraldthunder Před 3 lety +1

      I thought the voice sounded familiar.

  • @huonglarne
    @huonglarne Před 2 lety

    thanks. I love your examples, the ones that show how decorators might be used in real world situations. Very helpful

  • @michaelsvoboda1024
    @michaelsvoboda1024 Před 4 lety +4

    You made me begin using Kite. Thanks!

  • @zakariaabderrahmanesadelao3048

    Very grateful for your explanation. Decorators always confused me but through your detailed explanation and three very well described examples, I am more confident about decorators, thank you.

  • @amanullah5858
    @amanullah5858 Před 3 lety +1

    was confused earlier before watching it but you covered it in the best way... really loved your video

  • @miyalys
    @miyalys Před 3 lety

    Best decorator video I've seen so far. Thanks!

  • @DelivererVictor
    @DelivererVictor Před 6 měsíci

    this has to be the best explanation to decorators that I have seen. Amazing.

  • @pawjast
    @pawjast Před rokem

    Hands down the best explanation of Python decorators in the whole YT!

  • @facts_region
    @facts_region Před 2 lety

    Clean, Clear and Precise. Thanks

  • @AshwinLokkur
    @AshwinLokkur Před 4 lety +18

    Loved it. Quick, easy and accurate!

  • @bluefrog-wl2cu
    @bluefrog-wl2cu Před 3 měsíci

    I have seen lots of videos about Decorators. But Honestly It's the only video which helps me to understand the topic

  • @nursultankasym8417
    @nursultankasym8417 Před rokem

    thank you man, this video helped a lot to understand the decorators

  • @mohitsrivastava5880
    @mohitsrivastava5880 Před 3 lety

    Thank you for the precise and crisp information. Really helpful.

  • @robertschmidt8624
    @robertschmidt8624 Před 9 měsíci

    I still have some work to do with Decorators, but largely thanks to You I finally think
    I've got it.

  • @Wolfram69756D
    @Wolfram69756D Před 3 lety

    Finally a clear explanation of decorators! Many Thanks! :))

  • @Ben-kz2km
    @Ben-kz2km Před rokem +1

    Loved the examples at the end. I'm trying to figure out some best practices and cool use cases for decorators and it's really hard to find good information on when to use decorators and potential anti-patterns.

  • @jinettew.3192
    @jinettew.3192 Před rokem +1

    Bravo! This was REALLY well done. You nailed it.

  • @temik26
    @temik26 Před 3 lety

    This videos was so helpful to me. I have watched lots of videos before I got to this detailed explanation. Thank you so much!

  • @RedexTwo
    @RedexTwo Před rokem

    Thank you so much! I was struggling to understand this concept by reading resources online.

  • @floweast
    @floweast Před 2 lety

    you are the only one explained the decorator clearly!!!

  • @justinlua4848
    @justinlua4848 Před 2 lety

    I've never seen that before. I knew functions were objects but I never thought to use them like that. Very well explained.

  • @srikanthsukhavasi4860
    @srikanthsukhavasi4860 Před 2 lety

    I tried to understand Decorators from watching different videos. But trust me I used to be very confused after finishing the video. But, You made me understand Decorators very easily...Thank you.

  • @gavintantleff
    @gavintantleff Před 3 lety +4

    I love how to the point this video is to the point. No fluff, you just start explaining. Reminds me of Miziziziz tutorials.

    • @samszotkowski
      @samszotkowski Před 3 lety +1

      There's literally a minute of intro+ad

    • @MiguelAngel-fw4sk
      @MiguelAngel-fw4sk Před 2 lety

      Nope Mizziziziz doesn't put a minute of intro and ad at the beggining of his videos.

    • @gavintantleff
      @gavintantleff Před 2 lety

      @@MiguelAngel-fw4sk you're right

  • @afjalkasim5249
    @afjalkasim5249 Před rokem

    I see so many videos.but not clear how the function works .This is life changing.Krishna bless u sir

  • @deepayansarkar4258
    @deepayansarkar4258 Před rokem

    This is the best explanation I found over internet

  • @TotallyNotAuroras2ndChannel

    Nicely done. This is the first time I really paid attention to decorators

  • @elninolol
    @elninolol Před 2 měsíci

    I like the way the video starts with passing function as argument and print function address, very detailed and well explained for a beginner in Python like me. Thank you very much

  • @Stefadin
    @Stefadin Před rokem

    Thank you for this easy to follow tutorial. For me it just clicked when you showed us the examples.

  • @CraftyOldGit
    @CraftyOldGit Před 3 lety +2

    This is the best explanation of decorators I have seen, thank you. Kite is an interesting idea & I will try it out, but the 'Pro' version is far too expensive.

  • @radhika6212
    @radhika6212 Před 22 dny

    What an explanation, being a technical lead and doing automation in python for years..I would say my fundamentals are stronger now after going through this video..amazing work :)

  • @wonkim7951
    @wonkim7951 Před 4 měsíci

    this the best explanation about python decorator ever

  • @vikalpnarayan6243
    @vikalpnarayan6243 Před 4 měsíci

    Watched many videos on decorators but this is where my search ended.Excellent explanation!

  • @jamescarroll489
    @jamescarroll489 Před 2 lety

    Very concise with good examples. Thanks for the brown bag!

  • @AllanOlsen1970
    @AllanOlsen1970 Před 3 lety +1

    this was the best so far! thank you! :)

  • @heavencometandpros1093
    @heavencometandpros1093 Před 5 měsíci

    This is a really good decorator tutorial, understood it perfectly and helped me understand other concepts. Thank you!

  • @ISHIOYMO1
    @ISHIOYMO1 Před rokem

    You are awesome. Took me so many videos to get to this video. Now I finally understand Decorators. You make it so easy ! Thank you so much !

  • @Levendo
    @Levendo Před 9 měsíci

    I only had to pause at the start and look at your code for a few seconds to figure out where I was messing up. Thanks!

  • @svilenivanov3621
    @svilenivanov3621 Před 5 měsíci

    Great and useful, Tim! Appreciated.

  • @hackercop
    @hackercop Před 2 lety

    Now I understand decorators, thanks

  • @sjwang3892
    @sjwang3892 Před 3 lety

    I thank the world for having this video. God bless you

  • @69k_gold
    @69k_gold Před 2 měsíci

    Visualization really helps here. The f1(f) was what sparked my brain there

  • @rawats6751
    @rawats6751 Před 7 měsíci

    Thanks for your video, Now I got confidence on decorator never before. really appreciate well explained

  • @tearistovic
    @tearistovic Před 8 měsíci

    Thank youuu !!!! ☺❤❤

  • @dreamou6177
    @dreamou6177 Před 2 lety

    很实用,面试时候对装饰器我解释的总是不太好,看了你的视频,思路清晰了。

  • @anAlokDubey
    @anAlokDubey Před 2 lety

    Finally I understood the meaning of Decorators, thank you Kite :-) :-)

  • @dominiquecolin4716
    @dominiquecolin4716 Před 8 měsíci

    great job. I makes me feel I actually understood everything 😀

  • @Samuftie
    @Samuftie Před rokem

    brief and clear. thanks.

  • @Deevil992
    @Deevil992 Před 3 lety

    So clear. One of the best explanation on Python decorator 👍

  • @ahsenalimohammed7989
    @ahsenalimohammed7989 Před 3 lety +1

    Best video to understand Decorators. Really awesome explanation.

  • @KrampflOtto
    @KrampflOtto Před měsícem

    This was the best explanation, thank you :)

  • @fallenstar358
    @fallenstar358 Před 3 lety +1

    I am grateful thank to you I can understand and use decorators in Python!

  • @brettloo7588
    @brettloo7588 Před 2 lety

    Excellent explanation of the topic with good pace, clarity, and concise.

  • @owenpalmer8242
    @owenpalmer8242 Před rokem

    You are an excellent teacher!

  • @sayalimore5846
    @sayalimore5846 Před rokem

    Best explanation to date!

  • @dima1478
    @dima1478 Před 2 lety

    Crystal clear ty

  • @nejinii1353
    @nejinii1353 Před rokem

    Bro, Ive never seen a video tutorial where every second was clean and very precise such as yours!! Not to mention u updated my knowledghe on functions and decorators on to a whole new lelvel.
    The examples are not only great but usefull for anybody, also great tricks for our codes..
    Love you bro GREAT JOB!!!!

    • @pitchrollyawyeet
      @pitchrollyawyeet Před rokem +1

      Go check out the maker of this videos own channel for more by him @ TechWithTim

  • @ckks0nyoutube
    @ckks0nyoutube Před 10 měsíci

    Thanks, helped me get python decorators, at beginner level

  • @jaredfiacco1107
    @jaredfiacco1107 Před 5 měsíci

    Very helpful, thank you!

  • @yaqubadesola1839
    @yaqubadesola1839 Před 3 lety

    You actually deserve Nobel prize... Explanation to details

  • @curiousMe1000
    @curiousMe1000 Před rokem

    Mind Blowing and perfect explanation. Thank you so much

  • @Tetrick25
    @Tetrick25 Před 4 lety +15

    thanks for the perfect quality. Content, Voice, Speed, ...Just everything perfect

  • @dbly5460
    @dbly5460 Před 3 lety +1

    Very instructive ! Thank you so much

  • @siddharthupadhyay4246
    @siddharthupadhyay4246 Před 2 lety

    This is sooo goood. I was watching a udemy course on Python and couldnt understand the concept of decorators after multiple replays 😂 I am glad i watched this video.
    Thank You So Much:)

  • @amalkrishnas1696
    @amalkrishnas1696 Před rokem

    Thanks for the video, very helpful

  • @ollie_the_wandererli7523

    nice! i like all the things Kite does. keep going!

  • @sirio6990
    @sirio6990 Před 3 lety

    Really good explanation! Thank you.

  • @nhanLe_
    @nhanLe_ Před 2 lety

    Thank you. This is helpful

  • @lacikawiz8369
    @lacikawiz8369 Před 2 lety

    Thanks for making this video. It was very easy to follow and understand. Now I have another tool in my repertoire :)

  • @kilovolt2494
    @kilovolt2494 Před 2 lety +10

    Let me add a remark here.
    Decorators are truly awesome because they allow modifying the function(s) on the go without rewriting them. However, what if you have a loop where the function is called, and the decorator is set to print out value every time. You will end up with a hundred printed results?
    To save yourself from it, do a little trick:
    inside the wrapper, before the return statement, declare wrapper.original = func.
    If you just call the function, it will come out decorated. If you need the original function, call func.original(), and the wrapper will return it untouched.

  • @philiperiskallaleal6010
    @philiperiskallaleal6010 Před 2 lety +3

    Dear all, thank for the amazing video. Really well explained.
    I would like to ask you a specificity regarding decorator functions. In some use cases I have come across, I noticed that the __init__ method (of some user defined classes) is used as a decorator. Nevertheless, I couldn't figure out why or under which circumstance one should use it.
    Would you be so kind as to shed some light on this regard?
    Sincerely,

  • @thebuggser2752
    @thebuggser2752 Před 2 lety

    Very clear, precise and thorough presentation on decorators. Possibly the clearest I’ve seen online or in written form.
    I don’t think the concept of a decorator is a particularly intuitive one, even though Python bills itself, and usually is an intuitive programming language.. Seems to me that the Python team manufactured a construct that allows one to modify the behavior of a function without modifying the function itself.
    I’m still not sure that a decorator gives us something we couldn’t just as easily accomplished with just a few additional lines of code.
    However, still an excellent presentation. Thanks!

  • @absolutelynothingtoseehere

    You're a talented explainer

  • @azizkarimov7297
    @azizkarimov7297 Před rokem

    Amazing video, thanks for your help!

  • @slipperyorca8092
    @slipperyorca8092 Před 2 lety

    This is an amazing explanation!

  • @Ohy89
    @Ohy89 Před 2 lety

    Amazing tutorial, thanks!

  • @mohammadabbasi8968
    @mohammadabbasi8968 Před 2 lety

    Thank you soooo much bro!

  • @Rubbernecker
    @Rubbernecker Před rokem

    Well done!!! I think I get it now, thanks!