Skip to main content

← All terms · OOP

classmethod / staticmethod

`@classmethod` receives the class as `cls` (alternative constructors, class-level state). `@staticmethod` gets neither `self` nor `cls` — a function namespaced inside the class.

@classmethod
def from_string(cls, s): return cls(*s.split(","))

Learn this interactively:

Open lesson lesson-82

Related — OOP

ClassA blueprint for objects. Created with `class Foo:`. Defines attributes + methodsInstanceA specific object built from a class. `dog = Dog()` makes one instance of `Dog`.selfThe current instance, passed implicitly as the first argument to methods. By con__init__The constructor — runs when you call the class. Used to set instance attributes.Dunder methodsDouble-underscore methods that hook into Python syntax: `__add__`, `__len__`, `_InheritanceA class can inherit attributes and methods from a parent class: `class Dog(Anima