Caffeinated Coder
Book an appointment
Lesson 17 · Objects

Classes

A class is a blueprint for objects that carry their own data. Step through counter.py: class Counter: builds one class object holding two methods; calling Counter(5) makes a new object and __init__ fills in its count; c.add(2) finds add on the class and changes that one object from 5 to 7; a second object keeps its own count. Finish with the mistake every newcomer makes once: forgetting self.

14 min9 steps5 questionsIntermediate
Fig 17 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.