Python tricks: properties, staticmethods, and classmethods

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 พ.ย. 2024

ความคิดเห็น • 92

  • @mohit048
    @mohit048 7 ปีที่แล้ว +47

    Small and excellent video, really rare to see such tutorials, to the point & very nicely explained , Thumbs up for you !!!

    •  7 ปีที่แล้ว +4

      +mohit048 thank you!

    • @emmanuel.aggrey
      @emmanuel.aggrey 6 ปีที่แล้ว +2

      yes yes yes love your channel 💪

  • @realimaginary5328
    @realimaginary5328 8 หลายเดือนก่อน

    Wow!! Zero BS and straight to the point.

  • @jandrefelix3577
    @jandrefelix3577 3 ปีที่แล้ว +1

    Those guys are great but this explanation is more precise than that of Corey Shafer and Dereck Banas.
    Great job!

  • @aaronbaldwin2845
    @aaronbaldwin2845 3 ปีที่แล้ว

    Took 5 videos to try to grasp classmethod, but i think yours finally got me there... I think...

  • @satoshinakamoto171
    @satoshinakamoto171 4 ปีที่แล้ว +1

    this was really helpful . thanks. please keep making tutorials. u are helping the community !! bless you

  • @alvaromg8736
    @alvaromg8736 2 ปีที่แล้ว +1

    your explaining is 10/10

  • @slimyelow
    @slimyelow 5 ปีที่แล้ว +1

    This is an outstanding example that explained everything for me. Thanks !!

  • @nathalyliberalotto9812
    @nathalyliberalotto9812 2 ปีที่แล้ว

    Thanks for your video, now I understand clearly the decorator property.

  • @zacky7862
    @zacky7862 3 ปีที่แล้ว

    This is great tutorial. Now it's clearerto to me now the use and importance of those methods

  • @incognito13567
    @incognito13567 4 ปีที่แล้ว +1

    The coolest Python teacher :))). Ty 4 the video dude. It helped me a lot! :D

  • @KeenanKelsey
    @KeenanKelsey 4 ปีที่แล้ว +2

    If you apply these types of examples in all your python videos, you can create a product that kids in inner cities can grasp onto.

  • @stvv5546
    @stvv5546 3 ปีที่แล้ว +1

    Amazing! Thanks for sharing your knowledge! Very nice step-by-step teaching style!

  • @khaki714
    @khaki714 6 ปีที่แล้ว +16

    I hope someday I could understand it fully!

    •  6 ปีที่แล้ว +6

      Take your time and you will!

  • @ironmanlifts
    @ironmanlifts 3 ปีที่แล้ว +1

    Good explanation, looking forward to watching more videos.

  • @manohargujja
    @manohargujja 2 ปีที่แล้ว +1

    Just a clarification, in your pep8 coding guidelines videos, I see you saying coding convention for factory functions and i don't see the same while declaring the static method random_artist using @staticmethod decorator. Is it because you have defined the random_artist in a class or you should have defined it as RandomArtist. Please clarify.

    •  2 ปีที่แล้ว

      I would say it's a judgment call. Personally, I would use ThisNamingConvention only for functions that really look like they're classes. A static method, even if it returns an object, is clearly a function, and so I would personally use this_naming_convention. But in the end it's just a convention, and you should choose the naming style that will feel most intuitive to the user!

    • @manohargujja
      @manohargujja 2 ปีที่แล้ว

      @ thank you for the quick reply, what you say makes sense in a way.

  • @lucha0075db
    @lucha0075db 6 ปีที่แล้ว

    A statimethod can be used for anything, and not generally for any purpose. Say you want a method that when you pass it a number it multiplies it by 5. That method could easily be outside the class or if you want it to be inside, just add @staticmethod to it.

  • @dryhail
    @dryhail 5 ปีที่แล้ว +3

    Yoooo I'm super geeked and impressed with his knowledge of urban music! that's tight! good ish yo
    PS. Great explanation also....
    So the object, dunder class dunder hits (rr._class.__hits()) is a way around the "private" or mangled properties of certain attributes! Nice nice!

  • @banderilllero
    @banderilllero 4 ปีที่แล้ว +2

    Regarding staticmethod part:
    When I delete the "@staticmethod" line, the Code works in the Same way. Shouldnt it have some effect?

  • @fredericoamigo
    @fredericoamigo 2 ปีที่แล้ว +1

    Good, shot and consistent vid!

    •  2 ปีที่แล้ว

      Glad you like it! 😊

  • @MrDmitriM
    @MrDmitriM 5 ปีที่แล้ว +1

    One of the best explanation.

  • @nathanheath3756
    @nathanheath3756 6 ปีที่แล้ว +1

    dude this is so good! I completely understood how to use these after this video. subscribed!

    •  6 ปีที่แล้ว

      Glad you found it useful!

  • @mukulsabharwal8760
    @mukulsabharwal8760 5 ปีที่แล้ว +6

    that moment when you say YOung Jeezy - In the mix......

  • @mauroconsolani2576
    @mauroconsolani2576 4 ปีที่แล้ว

    Dude... Thank you for existing. Very clear!

  • @talat789
    @talat789 3 ปีที่แล้ว +2

    Nice explanation brother, keep up the good work 👍

  • @ShahbazAhmad-qz2iz
    @ShahbazAhmad-qz2iz 6 ปีที่แล้ว +15

    Dude u r just damn good 👏👏

    • @UPPERKEES
      @UPPERKEES 5 ปีที่แล้ว

      That's what she said.

  • @ranjit9427
    @ranjit9427 4 ปีที่แล้ว +2

    Great Content! Also Love ur FaceCam Style!!

  • @sudhansusekharsinku3954
    @sudhansusekharsinku3954 4 ปีที่แล้ว +1

    Nicely done

  • @mau_lopez
    @mau_lopez 6 ปีที่แล้ว +2

    Very useful and well explained, thanks a lot!

  • @sorvex9
    @sorvex9 2 ปีที่แล้ว +2

    I love this guy

  • @jnscollier
    @jnscollier 4 ปีที่แล้ว +1

    Super CLEAR!

  • @electricz3045
    @electricz3045 2 ปีที่แล้ว

    Instead of "Rick Ross" I always understand "Rick Rolls" lmao 😂

  • @mafridi106
    @mafridi106 6 ปีที่แล้ว

    Great explanation!! What terminal are you using that shows the code on top and output on the bottom?

    •  6 ปีที่แล้ว +1

      That's a Jupyter Notebook. Very convenient for cases where you want to show both the result of your code, and the code itself!

  • @fuanka1724
    @fuanka1724 6 ปีที่แล้ว +1

    10:13 isn't it simply adding a new field, called self._hits to the instance of the class?
    Great demonstration by the way, thanks.

    •  6 ปีที่แล้ว

      Yes, that's exactly what happens!

  • @hiteshthakur5025
    @hiteshthakur5025 3 ปีที่แล้ว

    Nicely explained.🔥

  • @eqbalelsid711
    @eqbalelsid711 6 ปีที่แล้ว

    this is packed with information!! thank you so much bro! great job

  • @disencd7953
    @disencd7953 6 ปีที่แล้ว

    Thanks Sebastiaan. I would love to follow your more and more tutorials. Keep it up :)

  • @chikosan99
    @chikosan99 3 ปีที่แล้ว

    Thanks for a great video!

  • @omarocampo7662
    @omarocampo7662 5 ปีที่แล้ว +1

    Awesome man. So thanks

  • @braian_nunes
    @braian_nunes 7 ปีที่แล้ว +1

    Very nice. Please upload more videos.

    •  7 ปีที่แล้ว +1

      There you go! th-cam.com/play/PLR-r0edywujd8D-R2Kue1C_wYEK_4Ii71.html

  • @lt_academy
    @lt_academy 2 ปีที่แล้ว +1

    really golden guy!

  • @slimyelow
    @slimyelow 5 ปีที่แล้ว

    I assume that random_artist() calls the class constructor TrapArtist in the return statement for this to work

  • @Dopeboyz789
    @Dopeboyz789 5 ปีที่แล้ว

    How do you use this method to match two dataframes

  • @dontbetoxic4387
    @dontbetoxic4387 3 ปีที่แล้ว

    How are ur sunglasses called?

  • @sn66410
    @sn66410 3 ปีที่แล้ว +1

    Awesome,

  • @saitaro
    @saitaro 7 ปีที่แล้ว +2

    Great stuff, thank you

  • @debvdo
    @debvdo 7 ปีที่แล้ว +1

    You said that static methods are used to implement factory functions. Aren't classmethods used for that? They are used to provide alternate constructors.

    •  7 ปีที่แล้ว

      That's a good point. Yes, you can use a class method for that as well, and they actually have a slight advantage, because they can use the cls argument to refer to the current class, rather than explicitly referring to it by name (as I'm doing in this video). That's especially convenient during subclassing. But you can use static methods as well in most cases.

  • @michaelolu4752
    @michaelolu4752 6 ปีที่แล้ว

    i use python 3.7 with a pycharm editor,...and its what i learned with. im not familiar with some methods you used like the getter method, and the part where you said there is a convention which you are required to place an undersore when creating a variable in self.....normally in pycharm, i just do 'self.name = name' and it works just fine. And i also dont need the getter method to print out a name from an object. i just do object.name, and it prints out the argument

    • @asaadnajjar5044
      @asaadnajjar5044 6 ปีที่แล้ว

      Michael Olu why are you watching if you don’t know what you are watching

    • @michaelolu4752
      @michaelolu4752 6 ปีที่แล้ว

      Asaad Najjar I'm trying to understand decorators in python

    • @asaadnajjar5044
      @asaadnajjar5044 6 ปีที่แล้ว

      1-This is more related to classes than it is to decorators
      2-knowing that a function returns a value, for some given data, assume you want to use that returned value in another function, so you use that function as an argument in the other function or you add the other function as a decorator, decorating the return of function one

    • @michaelolu4752
      @michaelolu4752 6 ปีที่แล้ว +2

      Asaad Najjar Well, I searched for decorators on youtube and it gave me this video. And obviously..@property, @staticmethod, and @classmethod are clearly decorators. So it's pretty much about decorators. 🙂

    • @charismaticaazim
      @charismaticaazim 5 ปีที่แล้ว +1

      @Micheal Olu : The underscore is used to make the variable visible / accessible only for methods within a class. These are similar to private variables in Java.
      To make those variables accessible you can use methods (like getters). A key advantage of using the getter n setter is that since it is a function, you can add some pre-processing login (e.g: Convert value to uppercase or append a string).
      Think about good practices for developing python code , rather than making the code just work. That'll make the code much more readable & maintainable in the long run.

  • @iworeushankaonce
    @iworeushankaonce 5 ปีที่แล้ว +1

    Damn, u really like Rick Ross. It's not the first time u mention his name in your tutorials

  • @kardashevr
    @kardashevr 6 ปีที่แล้ว

    I love the fact that you like hip-hop!

  • @tejasarlimatti8420
    @tejasarlimatti8420 5 ปีที่แล้ว

    great video!

  • @vdimit
    @vdimit 5 ปีที่แล้ว +2

    mooi! but why are you having those sunglasses :P

    •  5 ปีที่แล้ว +2

      I overcompensate.

  • @ShijoShajiValuzhathil
    @ShijoShajiValuzhathil 4 ปีที่แล้ว

    Thanks Seba

  • @StepanSmorkov
    @StepanSmorkov 5 ปีที่แล้ว

    Чувак, какой же ты крутой

  • @BijouBakson
    @BijouBakson ปีที่แล้ว

    Knows his code well, knows hiphop too! who said we're geeks huh??!!

  • @chborger185
    @chborger185 3 ปีที่แล้ว

    YESSS GREEN/BLUE/RED/BLACK --

  • @mbappekawani9716
    @mbappekawani9716 5 ปีที่แล้ว +1

    thank you

  • @neonz2712
    @neonz2712 2 ปีที่แล้ว +2

    What is that high-pitch ringing noise in the background? I would encourage you to run your video's audio through a pass-filter before publishing. Other than that, I'd say this is a great video! Not trying to be rude, I just thought you could use a bit of constructive criticism.

  • @rui_santos
    @rui_santos 6 ปีที่แล้ว

    When you don't use the underscore, the code gets into a infinite loop. Don't know why, but it happens.

    •  6 ปีที่แล้ว

      It sounds like you're having the name property return itself, is that right? That would indeed cause an infinite loop, in the same way that a function that (unconditionally) calls itself results in an infinite loop and eventually a RecursionErrror.

    • @rui_santos
      @rui_santos 6 ปีที่แล้ว

      Thank you m8. Great channel by the way.

  • @Naton
    @Naton 4 ปีที่แล้ว +1

    Damn... So cool

  • @jaspreetsahota1840
    @jaspreetsahota1840 7 ปีที่แล้ว

    Ricky Rosé approves this message

    •  7 ปีที่แล้ว

      +Jaspreet Sahota of course he does

  • @bulldawg4498
    @bulldawg4498 5 ปีที่แล้ว

    My red flag went up in the @classmethod discussion ...

  • @bhavanib3960
    @bhavanib3960 3 ปีที่แล้ว

    nice

  • @fentonmsu
    @fentonmsu 4 ปีที่แล้ว +1

    Geod un bedankt

  • @slimyelow
    @slimyelow 5 ปีที่แล้ว

    we want more !!

  • @anasbahi8371
    @anasbahi8371 5 ปีที่แล้ว

    JUST WOOW

  • @tianli8172
    @tianli8172 4 ปีที่แล้ว

    How do you know so many trap artists.. haha

  • @chborger185
    @chborger185 3 ปีที่แล้ว

    &&OO in a TOPdown VISUAL_Editor_what`s wrong? see my FUNCTION: DATA: ERROR :

  • @VarunKumar-pz5si
    @VarunKumar-pz5si 4 ปีที่แล้ว +1

    U look like Nick Jonas

    •  4 ปีที่แล้ว +1

      Jonas brother by day. Python coder by night.