Class Method
Introduction to OOP's
Class
Object
Constructor
Instance Variables
Class Variables
Instance Methods
self Keyword
Encapsulation
Public Members
Protected Members
Private Members
Inheritance
Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Hybrid Inheritance
super() Function
Polymorphism
Method Overriding
Duck Typing
Abstraction
Abstract Class
Abstract Method
Class Method
Static Method
Special Methods
_str_ Method
Operator Overloading
Composition
Aggregation
Association
Method Resolution Order
Object Class
issubclass() and isinstance()
Property Decorator
Setter Method with @property
Destructor
Inner Class
Complete Mini Example
Class Method
25. Class Method
A class method works with the class itself rather than a specific object and uses cls as the first parameter. It is declared using the @classmethod decorator.
Syntax
@classmethod
def method(cls):
pass
Example
class College:
name = "National College"
@classmethod
def show_name(cls):
print(cls.name)
College.show_name()
Output
National College
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Class Method to test your knowledge.
Browse Quizzes »