Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
A regular method receives the instance as self, a classmethod receives the class as cls, and a staticmethod receives neither and is just a function grouped inside the class.
Regular methods work with a specific object's data. Class methods receive cls, so they can create instances, which makes them ideal for alternative constructors like Date.from_string('2024-01-01'), and they work correctly with subclasses because cls is the subclass. Static methods have no access to the instance or the class unless passed in; they are used for helper logic that belongs to the class conceptually. If a static method does not really relate to the class, a module-level function is often simpler.