When should you use a class versus a function?
Common pitfalls and best practices
Audio flashcard · 0:16Nortren·
When should you use a class versus a function?
0:16
Use a function for stateless operations and pure computations. Use a class when you need to maintain state across multiple operations, when several functions naturally share the same data, or when polymorphism makes the design cleaner. Resist the urge to wrap a single function in a class.
docs.python.org