Learn Python
>>> oop_fundamentals.methods_types

Instance, Class & Static Methods in Python

#concept

Python has three kinds of methods, each receiving different implicit information: an instance method (the default) automatically receives the specific instance it was called on as self; a class method, marked with @classmethod, receives the class itself as cls instead; a static method, marked with @staticmethod, receives neither, behaving like a plain function that simply lives inside the class for organization.

#how it works
1

Instance methods take self

Giving access to that specific instance’s data.

2

@classmethod methods take cls

Giving access to the class itself, not any particular instance.

3

@staticmethod methods take neither

They don’t need instance or class data at all.

4

Class methods make good alternative constructors

Building and returning a new instance in a different way than __init__() does.

5

Static methods group related utilities

Purely for organizing a standalone helper function inside the class it logically belongs to.

#example
class Pizza:
def __init__(self, toppings):
self.toppings = toppings
 
@classmethod
def margherita(cls):
return cls(["tomato", "mozzarella"])
 
@staticmethod
def is_valid_topping(topping):
return topping in ["tomato", "mozzarella", "basil", "pepperoni"]
 
p1 = Pizza.margherita()
print(p1.toppings)
print(Pizza.is_valid_topping("pineapple"))
Output
['tomato', 'mozzarella']
False
1Pizza.margherita() is called on the class itself, not an instance — cls refers to Pizza, and the method builds and returns a new Pizza instance with preset toppings.
2Pizza.is_valid_topping("pineapple") is also called on the class, but it doesn’t need cls or self at all — it’s just a plain check, grouped inside Pizza for organization.
3Neither call required creating a Pizza instance first, unlike a regular instance method would.
#use cases
Alternative constructors, like Pizza.margherita() building a preset instance without repeating the full argument list
Utility functions that logically belong to a class but don't need any instance or class data, like a validation check
Factory methods that return an instance of a subclass depending on some input, using cls rather than hardcoding the class name
Keeping related helper logic organized inside the class it supports, instead of scattered as free-floating functions

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.