AI engineering glossary · Python advanced

What is class method?

Class method (also called @classmethod): A method bound to the class instead of an object, marked with @classmethod and receiving the class as its first argument (usually cls). It is often used as an alternative constructor.

Level: intermediateTopic: Python advanced

Class method: an example

@classmethod def from_csv(cls, path): return cls(read(path)) builds an object from a file, e.g. Dataset.from_csv('sales.csv').

Related terms

More Python advanced terms

Where you learn it

Class method is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.