Nearby lessons

88 of 108

Python - Static Methods

What Is a Static Method?

A static method is a method that does not use self or cls.

It is usually used for utility operations.

Syntax

class Demo:
    @staticmethod
    def add(x, y):
        return x + y

Example

class DurgaMath:
    @staticmethod
    def add(x, y):
        print("The Sum:", x + y)

Important Points

  • Use the @staticmethod decorator
  • No implicit self parameter
  • Can be called using the class name or object reference

Summary

Term Meaning
@staticmethodDefines a static method
selfNot required
clsNot required

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!Python - Class Methods