Methods (Instance, Class, Static)
Python has three types of methods: instance methods (self), class methods (@classmethod, cls), and static methods (@staticmethod, no self/cls).
15 min•By Priygop Team•Updated 2026
Method Types
Method Types
class MathUtils:
pi = 3.14159 # class attribute
def __init__(self, value):
self.value = value # instance attribute
# Instance method — operates on instance data
def square(self):
return self.value ** 2
# Class method — operates on class data
@classmethod
def circle_area(cls, radius):
return cls.pi * radius ** 2
# Static method — utility, no access to class/instance
@staticmethod
def add(a, b):
return a + b
# Instance method
m = MathUtils(5)
print(f"5² = {m.square()}")
# Class method (can call without instance)
print(f"Circle area (r=3): {MathUtils.circle_area(3):.2f}")
# Static method
print(f"5 + 3 = {MathUtils.add(5, 3)}")
# Practical: alternative constructors
class Date:
def __init__(self, year, month, day):
self.year = year
self.month = month
self.day = day
@classmethod
def from_string(cls, date_str):
year, month, day = map(int, date_str.split("-"))
return cls(year, month, day)
def __str__(self):
return f"{self.year}-{self.month:02d}-{self.day:02d}"
d = Date.from_string("2024-01-15")
print(d) # 2024-01-15Tip
Tip
Use @classmethod for alternative constructors: Date.from_string('2024-01-15'). Use @staticmethod for utility functions that don't need class/instance data.
Diagram
Loading diagram…
Classes are syntactic sugar over prototypes.
Common Mistake
Warning
Confusing instance, class, and static methods. Instance uses self, classmethod uses cls, staticmethod uses neither.
Practice Task
Note
(1) Create a class with all 3 method types. (2) Build a from_string classmethod. (3) Add a validation staticmethod.