Python tricks: properties, staticmethods, and classmethods

Поделиться
HTML-код
  • Опубликовано: 9 фев 2025

Комментарии • 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 💪

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

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

  • @realimaginary5328
    @realimaginary5328 10 месяцев назад

    Wow!! Zero BS and straight to the point.

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

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

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

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

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

    Good, shot and consistent vid!

    •  3 года назад

      Glad you like it! 😊

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

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

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

    your explaining is 10/10

  • @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

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

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

  • @KeenanKelsey
    @KeenanKelsey 5 лет назад +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.

  • @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!

  • @khaki714
    @khaki714 6 лет назад +16

    I hope someday I could understand it fully!

    •  6 лет назад +6

      Take your time and you will!

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

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

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

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

  • @talat789
    @talat789 3 года назад +2

    Nice explanation brother, keep up the good work 👍

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

    Good explanation, looking forward to watching more videos.

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

    Nicely done

  • @MrDmitriM
    @MrDmitriM 6 лет назад +1

    One of the best explanation.

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

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

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

    Nicely explained.🔥

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

    Great Content! Also Love ur FaceCam Style!!

  • @sorvex9
    @sorvex9 3 года назад +2

    I love this guy

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

    Super CLEAR!

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

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

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

    Thanks for a great video!

  • @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?

  • @mau_lopez
    @mau_lopez 6 лет назад +2

    Very useful and well explained, thanks a lot!

  • @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!

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

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

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

    really golden guy!

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

    Awesome,

  • @disencd7953
    @disencd7953 6 лет назад

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

  • @neonz2712
    @neonz2712 3 года назад +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.

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

    Awesome man. So thanks

  • @eqbalelsid711
    @eqbalelsid711 6 лет назад

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

  • @ShahbazAhmad-qz2iz
    @ShahbazAhmad-qz2iz 6 лет назад +15

    Dude u r just damn good 👏👏

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

      That's what she said.

  • @braian_nunes
    @braian_nunes 7 лет назад +1

    Very nice. Please upload more videos.

    •  7 лет назад +1

      There you go! ruclips.net/p/PLR-r0edywujd8D-R2Kue1C_wYEK_4Ii71

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

    thank you

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

    How do you use this method to match two dataframes

  • @saitaro
    @saitaro 7 лет назад +2

    Great stuff, thank you

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

    How are ur sunglasses called?

  • @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!

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

  • @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!

  • @iworeushankaonce
    @iworeushankaonce 6 лет назад +1

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

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

    Thanks Seba

  • @tejasarlimatti8420
    @tejasarlimatti8420 6 лет назад

    great video!

  • @kardashevr
    @kardashevr 6 лет назад

    I love the fact that you like hip-hop!

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

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

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

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

    nice

  • @jaspreetsahota1840
    @jaspreetsahota1840 7 лет назад

    Ricky Rosé approves this message

    •  7 лет назад

      +Jaspreet Sahota of course he does

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

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

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

    mooi! but why are you having those sunglasses :P

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

      I overcompensate.

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

    YESSS GREEN/BLUE/RED/BLACK --

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

    Damn... So cool

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

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

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

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

    Geod un bedankt

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

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

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

    we want more !!

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

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

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

    JUST WOOW

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

    How do you know so many trap artists.. haha

  • @VarunKumar-pz5si
    @VarunKumar-pz5si 4 года назад +1

    U look like Nick Jonas

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

      Jonas brother by day. Python coder by night.