MemotivaClass methods, static methods, and metaclasses

When would you use a class method as an alternative constructor?

Class methods, static methods, and metaclasses

Audio flashcard · 0:14

Nortren·

When would you use a class method as an alternative constructor?

0:14

Class methods are ideal for alternative constructors that build instances from different inputs. For example, a Date class might have from_string and from_timestamp class methods that parse their arguments and call the regular init. This pattern is common in the standard library, including in datetime.
docs.python.org