PYnative

Practice Coding

  • Python ▼
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Coding Exercises ▼
    • Python Exercises
    • C++ Exercises
    • C Programming Exercises
    • Java Exercises
    • C# Exercises
  • MCQs▼
    • Python MCQ Quizzes
    • Java MCQ Quizzes
    • C++ MCQ Quizzes
  • Compilers▼
    • Online Python Compiler
    • Online C Compiler
    • Online C++ Compiler
    • Online Java Compiler
    • Online C# Compiler
Home » Python » Python Object-Oriented Programming (OOP) » Python Static Method Explained With Examples

Python Static Method Explained With Examples

Updated on: December 4, 2026 | 4 Comments

In object-oriented programming, besides instance methods, we can define class methods and static methods in a class.

  • Class methods: Used to access or modify the state of the class. If a method uses only class variables, declare it as a class method.
  • Static methods: A static method is a general utility method that performs a task in isolation. It doesn’t use instance or class variables, because it doesn’t receive self or cls.

Also, read Python Class method vs Static method vs Instance method.

After reading this article, you’ll learn:

  • How to create and use static methods in Python
  • How to create a static method using the @staticmethod decorator and the staticmethod() function
  • When to use a static method, and when not to
  • How to call a static method from other methods

Table of contents

  • What is Static Methods in Python
  • Define Static Method in Python
    • Example: Create Static Method Using @staticmethod Decorator
  • Advantages of a Static Method
  • When to Use a Static Method
  • The staticmethod() function
  • Call Static Method from Another Method
  • Summary

What is Static Methods in Python

A static method is a general utility method that performs a task in isolation. Static methods in Python are similar to static methods in Java or C++.

A static method belongs to the class namespace, but it isn’t bound to the class or to an object. It’s a plain function placed inside the class because it’s logically related to it. We usually call it using the class name.

A static method doesn’t have access to class or instance variables, because it doesn’t receive an implicit first argument like self or cls. Therefore, it can’t modify the state of the object or the class.

A static method can be called using ClassName.method_name() or through an object of the class.

class Employee:
    @staticmethod
    def sample(x):
        print('Inside static method', x)

# call static method
Employee.sample(10)

# can be called using object
emp = Employee()
emp.sample(10)Code language: Python (python)

Output:

Inside static method 10
Inside static method 10

Define Static Method in Python

Every method you define in a class is an instance method by default. To make it a static method, you must tell Python explicitly using the @staticmethod decorator or the staticmethod() function.

Static methods are defined inside a class, much like a regular function. To declare a static method, use this idiom:

class C:
    @staticmethod
    def f(arg1, arg2, ...): ...Code language: Python (python)

Example: Create Static Method Using @staticmethod Decorator

To make a method a static method, add the @staticmethod decorator before the method definition. Don’t add self or cls as a parameter.

@staticmethod is a built-in decorator. Python applies it right after the function is defined and turns the function into a static method.

Sometimes you’ll write code that belongs to a class but doesn’t use the object itself at all. Such a utility method doesn’t need an object (the self parameter) to do its job, so we declare it as a static method. Other methods of the class can still call it.

In this example, we create a static method gather_requirement() that accepts a project name and returns all the tasks required to complete that project.

class Employee:

    def __init__(self, name, salary, project_name):
        self.name = name
        self.salary = salary
        self.project_name = project_name

    @staticmethod
    def gather_requirement(project_name):
        if project_name == 'ABC Project':
            requirement = ['task_1', 'task_2', 'task_3']
        else:
            requirement = ['task_1']
        return requirement

    # instance method
    def work(self):
        # call static method from instance method
        requirement = self.gather_requirement(self.project_name)
        for task in requirement:
            print('Completed', task)

emp = Employee('Kelly', 12000, 'ABC Project')
emp.work()Code language: Python (python)

Output:

Completed task_1
Completed task_2
Completed task_3

Advantages of a Static Method

A static method has the following advantages:

  • Readability: When you see @staticmethod above a method, you immediately know that the method doesn’t depend on the object’s state or the class state.
  • Utility functions with a clear home: Static methods can’t access an object’s attributes (instance variables) or class attributes (class variables). This makes them a good fit for helpers such as validation or converting a value from one unit to another, where the parameters provide everything the method needs. Keeping them inside the class groups them with related code.
  • No binding needed: Python doesn’t need to bind a static method to an object. When you access it through an object or the class, you get the same plain function every time.

Note: A common myth is that every object gets its own copy of each instance method, and that static methods save memory. That’s not true. All methods, of every kind, are stored only once, in the class. When you access an instance method through an object, Python creates a small temporary bound method that links the function to that object. That’s why kelly.work is jessa.work is False, even though both use the same function. The following code shows this.

kelly = Employee('Kelly', 12000, 'ABC Project')
jessa = Employee('Jessa', 7000, 'XYZ Project')

# instance method: a new bound method object is created on each access
print(kelly.work is jessa.work)    # False
print(kelly.work is kelly.work)    # False

# but the underlying function is stored only once, in the class
print(kelly.work.__func__ is jessa.work.__func__)    # True

# static method: no binding, you get the same plain function every time
print(kelly.gather_requirement is jessa.gather_requirement)       # True
print(kelly.gather_requirement is Employee.gather_requirement)    # TrueCode language: Python (python)

When to Use a Static Method

Use a static method when the method:

  • doesn’t need to read or change instance variables (no self), and
  • doesn’t need to read or change class variables or create objects of the class (no cls), but
  • is closely related to the class, so it makes sense to keep it there.

If the method needs the class (for example, to create a new object or read a class variable), use a class method instead. If it isn’t related to the class at all, a regular module-level function is often simpler.

Example: A temperature class with static helper methods for conversion and validation.

class Temperature:
    @staticmethod
    def celsius_to_fahrenheit(c):
        return c * 9 / 5 + 32

    @staticmethod
    def is_valid(c):
        # -273.15 is absolute zero
        return c >= -273.15

    def __init__(self, celsius):
        if not Temperature.is_valid(celsius):
            raise ValueError('Temperature below absolute zero')
        self.celsius = celsius

    def show(self):
        # call static method from instance method
        print(self.celsius, 'C =', self.celsius_to_fahrenheit(self.celsius), 'F')

print(Temperature.celsius_to_fahrenheit(100))
t = Temperature(25)
t.show()
print(Temperature.is_valid(-300))Code language: Python (python)

Output:

212.0
25 C = 77.0 F
False

The staticmethod() function

Some older code defines static methods by calling staticmethod() as a function rather than using it as a decorator.

The decorator syntax has been available since Python 2.4, so in modern code you should always use the @staticmethod decorator. The staticmethod() function is mainly useful when you add a static method to a class at runtime.

Syntax:

staticmethod(function)Code language: Python (python)
  • function: The function you want to convert into a static method.
  • It returns the converted static method.

Example:

class Employee:
    def sample(x):
        print('Inside static method', x)

# convert to static method
Employee.sample = staticmethod(Employee.sample)
# call static method
Employee.sample(10)Code language: Python (python)

Output:

Inside static method 10

The staticmethod() approach is helpful when you need to store a reference to a function in a class and you want to stop Python from automatically turning it into an instance method.

Call Static Method from Another Method

You can call a static method from any other method of the same class:

  • From an instance method: self.static_method() (as in the work() example above)
  • From a class method: cls.static_method()
  • From another static method: ClassName.static_method(), because a static method has no self or cls

In the following example, a class method calls a static method, which in turn calls another static method.

class Test:
    @staticmethod
    def static_method_1():
        print('static method 1')

    @staticmethod
    def static_method_2():
        Test.static_method_1()

    @classmethod
    def class_method_1(cls):
        cls.static_method_2()

# call class method
Test.class_method_1()Code language: Python (python)

Output:

static method 1

Summary

  • A static method is a utility function defined inside a class. It takes neither self nor cls.
  • Create it with the @staticmethod decorator (preferred) or the staticmethod() function.
  • It can’t access or modify instance variables or class variables.
  • Call it with ClassName.method() or through an object.
  • Use it for helpers that are related to the class but don’t need its data. Use a class method if you need the class.
  • Static methods don’t save memory compared to instance methods. Every method is stored once in the class.

Reference: Static method documentation

Filed Under: Python, Python Object-Oriented Programming (OOP)

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Object-Oriented Programming (OOP)

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises
Java Exercises
C# Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes
In: Python Python Object-Oriented Programming (OOP)
TweetF  sharein  shareP  Pin

  Python OOP

  • Python OOP
  • Classes and Objects in Python
  • Constructors in Python
  • Python Destructors
  • Encapsulation in Python
  • Polymorphism in Python
  • Inheritance in Python
  • Python Instance Variables
  • Python Instance Methods
  • Python Class Variables
  • Python Class Method
  • Python Static Method
  • Python Class Method vs. Static Method vs. Instance Method
  • Python OOP exercise

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

Python Basics Python Exercises Python Quizzes Python Interview Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

About PYnative

PYnative.com is a platform built to help developers learn by doing. Solve coding exercises, take MCQs, and run code directly in built-in online compilers.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises
  • Java Exercises
  • C# Exercises

MCQ Quizzes

  • Python MCQs
  • Java MCQs
  • C++ MCQs

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2026 pynative.com