Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Python Method Types Recap & Review

This is the last video of the course providing you a quick recap of what you have learned so far about the three different method types.

Want more? Keep improving your Python OOP skills with our Object-Oriented Programming (OOP) With Python Learning Path.

sumankalyanr on June 12, 2019

Super cool explanation on method types in python.. I thoroughly enjoyed it.

Dan Bader RP Team on June 12, 2019

@sumankalyanr: Thanks, that’s great to hear!

victorariasvanegas on June 22, 2019

Great explanation , I’m really enjoying this class.

DiscreteLoner on June 27, 2019

Awesome! I really enjoy this video set.

Technocrats Warnakala on Aug. 9, 2019

super cool, it would be awesome if we get references to real world implementation as well, probably link to github/gitlab projects which has the usage of OOP Method

LJIN Lab on Aug. 10, 2019

Great tutorial, but real world examples would be great!

ThangHoang on Aug. 21, 2019

Awesome, Thank you so much

blaqhrse on Sept. 22, 2019

Thanks Dan; clear explanation but would like to echo the same as previous posts. Real world examples would really help drive it home.

mikesult on March 3, 2020

Thanks for another good tutorial and thanks for the links to stackoverflow. There’s a lot of different opinions to digest.

Zarata on April 20, 2020

I like the short, digestable (no Pizza pun intended, but I’ll take it), and on point. Thanks! IF I’m right and the “magic” is in the decorators to make things work one way or other, you might want to make special note of that. I’ve only seen decorator use here and there in the trails I’ve been following and I’ve already forgotten the bits I’ve seen.

Zarata on April 20, 2020

Sorry … digestible.

Im sorry man, but I didnt find good information from this tutorial. Perhaps more and different use cases. I would have preferred a longer tutorial if it meant more and clear guidance on this topic.

Erikton Konomi on May 20, 2020

Thanks Dan, but have to agree with others. The links from stackoverflow have some good information, but a couple solid examples in the tutorial itself would have been preferable.

I found this example helpful: stackabuse.com/pythons-classmethod-and-staticmethod-explained/

sroux53 on June 8, 2020

Excellent !

Ghani on Oct. 7, 2020

Good but “too compact”!

Mark Walle on Dec. 2, 2020

Here is a bit of a deeper dive on this subject matter that still involves pizza (found via one of Dan’s stackoverflow posts linked above):

julien.danjou.info/guide-python-static-class-abstract-methods/

boardtc on Jan. 27, 2021

@Mark Walle, thanks for link, that article explains about bounded & unbounded methods which gave me further understanding into the python way. One thing I wonder is does a method have to be either a class/cls method, a bound/self method, a static method or an abstract method…there are no other options for it to be just a method?

ephremworkeye on Aug. 16, 2021

Thank you so much!!! I have one question though: when we call @classmethod like Pizza.margherita(), does it mean we have created instance of class or object?

Thanks

Martin Breuss RP Team on Aug. 16, 2021

Hi @ephremworkeye. Is it correct that you’re thinking of a @classmethod called margherita() that’s part of the Pizza class:

class Pizza:

    @classmethod
    def margherita(cls):
        return "It's a pi'zza!"

This toy implementation doesn’t make much sense as a @classmethod, considering that the cls argument isn’t used in the body of the method. But since that’s not the point of your question, we can let it slide :)

So if you’re calling a @classmethod called margherita() that’s part of the Pizza class, then you can get the following output:

>>> Pizza.margherita()
"It's a pi'zza!"

>>> Pizza.margherita() == Pizza().margherita()
True

>>> Pizza.margherita
<bound method Pizza.margherita of <class '__main__.Pizza'>>

Where do you think the @classmethod belongs to when you look at this output, and what’s your interpretation of the results? Can you come up with another test that might help answer your question?

Tony Florido on Dec. 26, 2021

@ephremworkeye instance of the class.

Become a Member to join the conversation.