Python Reference Library →

Python staticmethod() Function – Create Static Methods in Classes

Let’s look at staticmethod() function – create static methods in classes

  1. Notice

    A staticmethod receives neither an implicit instance nor an implicit class. Its arguments come from the call.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
class Math:
    @staticmethod
    def double(number):
        return number * 2
print(Math.double(3))
Live state

Top-level scope

Math→Object 2
Object 2 · typeclass Math
This step

A staticmethod receives neither an implicit instance nor an implicit class. Its arguments come from the call.

Picture staticmethod() function – create static methods in classes

A staticmethod receives neither an implicit instance nor an implicit class. Its arguments come from the call.

Image brief

Alt text
A diagram for Python staticmethod() Function – Create Static Methods in Classes. Instructions: class Math: @staticmethod def double(number): return number * 2 print(Math.double(3)). Displayed result: 6. The final example bindings are Math --> object 2 (type). object 2: class Math
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python staticmethod() Function – Create Static Methods in Classes". Teaching focus: A staticmethod receives neither an implicit instance nor an implicit class. Its arguments come from the call. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS class Math: @staticmethod def double(number): return number * 2 print(Math.double(3)) | v DISPLAYED RESULT 6 FINAL BINDINGS Math --> object 2 (type) object 2: class Math Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python staticmethod() Function – Create Static Methods in Classes. Instructions: class Math: @staticmethod def double(number): return number * 2 print(Math.double(3)). Displayed result: 6. The final example bindings are Math --> object 2 (type). object 2: class Math

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
class Math:
    @staticmethod
    def double(number):
        return number * 2
print(Math.double(3))
Live state

Top-level scope

Math→Object 2
Object 2 · typeclass Math
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
6

What do you expect this program to print?

What does this example display?

class Math:
    @staticmethod
    def double(number):
        return number * 2
print(Math.double(3))
What does this example display?
Choose one answer. You can try again.

Answer and explanation

6

Follow the printed values in order. The output is: 6

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

A staticmethod receives neither an implicit instance nor an implicit class. Its arguments come from the call.

A staticmethod receives neither an implicit instance nor an implicit class. Its arguments come from the call.

More examples and reference

Python staticmethod() Function

The staticmethod() function in Python is used to define a static method inside a class. A static method doesn't take the instance (self) or class (cls) as the first argument. It behaves like a regular function but belongs to the class’s namespace.

Syntax

staticmethod(function)

Parameter:

  • function – A function you want to convert into a static method.

Returns:

  • A static method object that can be called on the class or its instances.

Example: Creating a Static Method

class MathUtils:
    @staticmethod
    def add(a, b):
        return a + b

# Call without creating an object
print(MathUtils.add(5, 3))
8

Example: Without Decorator

You can also use staticmethod() without the @staticmethod decorator:

class MathUtils:
    def add(a, b):
        return a + b

    add = staticmethod(add)

print(MathUtils.add(10, 4))
14

Use Case: When to Use staticmethod()?

  • When the method doesn’t need access to the instance or class.
  • Utility functions that logically belong to the class, but don’t use class or instance data.

Comparison: staticmethod vs classmethod

Featurestaticmethod()classmethod()
Access to instance?NoNo
Access to class?NoYes
First argumentNonecls
Use caseHelper functionsFactory methods

Common Mistakes

  • Trying to use self or cls inside a static method – it won’t work.
  • Not using @staticmethod decorator or staticmethod() function – method acts as a normal one and expects self.

Interview Tip

Interviewers often ask the difference between staticmethod() and classmethod(). Know when and why to use each.

Summary

  • staticmethod() makes a function callable via the class without needing an object.
  • It doesn’t access or modify class or instance state.
  • Perfect for utility/helper methods inside a class.

Practice Problem

Create a class Temperature with a static method celsius_to_fahrenheit(c) that converts Celsius to Fahrenheit.

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

print(Temperature.celsius_to_fahrenheit(37))

Expected Output:

98.6

What to remember

Connect what you noticed in the example with the idea below.

Remember

A staticmethod receives neither an implicit instance nor an implicit class. Its arguments come from the call.

Watch out for this idea

A staticmethod always receives self automatically.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →