Home Tutorials Python OOP Concepts Class Method
Class Method

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

🏋️ Test Yourself With Exercises

Take our quiz on Class Method to test your knowledge.

Browse Quizzes »