cls (argument)

In Python, cls is a conventional name for the first argument of a class method.

When you define a class method using the @classmethod decorator, the method’s first argument—which is required—will hold a reference to the class itself. Conventionally, this argument is calls cls and allows you to use the class object inside the method.

Following this naming convention will make your code Pythonic and familiar to other Python developers.

Example

Here’s an example illustrating the use of cls in a class method:

Python demo.py
class DemoClass:
    class_variable = "Hello, Class!"

    @classmethod
    def show_class_variable(cls):
        print(cls.class_variable)

# Usage
DemoClass.show_class_variable()  # Output: Hello, Class!

In this example, .show_class_variable() is a class method, and cls is used to access .class_variable from the class itself.

Tutorial

Python's Instance, Class, and Static Methods Demystified

In this tutorial, you'll compare Python's instance methods, class methods, and static methods. You'll gain an understanding of when and how to use each method type to write clear and maintainable object-oriented code.

intermediate python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated April 10, 2025 • Reviewed by Leodanis Pozo Ramos