staticmethod()

staticmethod(function)
Returns: method · Updated March 13, 2026 · Built-in Functions
built-in oop methods

The staticmethod() function returns a static method for a function. Static methods behave like regular functions within a class but don’t receive the implicit self (instance) or cls (class) as their first argument. They’re typically used as decorators (@staticmethod) to define utility functions that logically belong to a class but don’t require access to instance or class state.

Syntax

staticmethod(function)

Parameters

ParameterTypeDefaultDescription
functioncallableThe function to be converted into a static method

Examples

Using the decorator syntax

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

    @staticmethod
    def fahrenheit_to_celsius(f):
        return (f - 32) * 5/9

# Call directly on the class — no instance needed
print(Temperature.celsius_to_fahrenheit(100))
# 212.0

print(Temperature.fahrenheit_to_celsius(212))
# 100.0

Static methods work on instances too, but there’s no advantage to doing so:

t = Temperature()
print(t.celsius_to_fahrenheit(0))
# 32.0

Factory pattern with static methods

Static methods are useful for factory methods that create class instances:

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    @staticmethod
    def from_tuple(coords):
        return Point(coords[0], coords[1])

    @staticmethod
    def from_dict(d):
        return Point(d['x'], d['y'])

# Create points using different input formats
p1 = Point.from_tuple((10, 20))
p2 = Point.from_dict({'x': 5, 'y': 15})

print(p1.x, p1.y)  # 10 20
print(p2.x, p2.y)  # 5 15

Common Patterns

Validation and utility functions

Static methods work well for validation logic that relates to a class but doesn’t need instance data:

class User:
    def __init__(self, username, email):
        self.username = username
        self.email = email

    @staticmethod
    def validate_email(email):
        return '@' in email and '.' in email.split('@')[-1]

    @staticmethod
    def validate_username(username):
        return len(username) >= 3 and username.isalnum()

# Validate before creating
if User.validate_email("test@example.com"):
    user = User("testuser", "test@example.com")

Use static methods to keep related utility functions organized under a class namespace:

class MathUtils:
    @staticmethod
    def average(numbers):
        return sum(numbers) / len(numbers)

    @staticmethod
    def median(numbers):
        sorted_nums = sorted(numbers)
        n = len(sorted_nums)
        if n % 2 == 0:
            return (sorted_nums[n//2-1] + sorted_nums[n//2]) / 2
        return sorted_nums[n//2]

    @staticmethod
    def mode(numbers):
        from collections import Counter
        return Counter(numbers).most_common(1)[0][0]

print(MathUtils.average([1, 2, 3, 4, 5]))  # 3.0
print(MathUtils.median([1, 2, 3, 4, 5]))   # 3

See Also