OOP Method Types in Python: @classmethod vs @staticmethod vs Instance Methods
Dan Bader
7 Lessons
14m
intermediate
python
What’s the difference between @classmethod, @staticmethod, and “plain/regular” instance methods in Python? You’ll know the answer after watching this video course:
-
Regular (instance) methods need a class instance and can access the instance through
self. They can read and modify an objects state freely. -
Class methods, marked with the
@classmethoddecorator, don’t need a class instance. They can’t access the instance (self) but they have access to the class itself viacls. -
Static methods, marked with the
@staticmethoddecorator, don’t have access toclsorself. They work like regular functions but belong to the class’s namespace.
In this course you’ll go over the differences between these three kinds of methods in Python. You’ll also see when to use each with a simple example, so you can improve your object-oriented programming (OOP) skills in Python.
Recommended Resources
OOP Method Types in Python: @classmethod vs @staticmethod vs Instance Methods
7 Lessons ⋅ 14m
About Dan Bader
Dan is the Chief Python Nut at Real Python. He helps Python developers take their coding skills to the next level with Python tutorials, books, and online training.
» More about Dan
