Lessons › coding and computer science · taught by Leo
Classes and objects: blueprint vs instance
Learn the difference between a class, an object, properties, and methods in Python with simple examples.
Learn this with Leo, freeA voiced lesson with a live whiteboard, quizzes and a tutor you can call, at tutelage.appA class is a blueprint
A class is like a blueprint. It tells you what every object of that type should have and do.
The objects are the real things built from it.
Class vs object
A class is the plan. An object is one specific thing made from that plan.
Think of a class like a cookie cutter.
Think of an object like one cookie made from it.
Same shape, separate cookie.
Predict the match
If a class is a blueprint, what is an object?
- The actual thing made from the blueprint
- The blueprint itself
- A mistake in the code
Show answer
The actual thing made from the blueprint: Yes. An object is one real instance made from the class.
Make one object from a class
Here is the pattern. First you define the class.
Then you add properties and methods. Those describe what each object can store and do.
Last, you create one object from the class.
What does this make?
What does Car() usually create?
- A class
- An object
- A comment
Show answer
An object: Correct. Car() creates an object, also called an instance.
Properties hold data
Properties are the data on the object. Methods are the actions.
That split helps you organize code into things and behaviors.
Why objects are useful
Objects keep related data and actions together, so your code is easier to read and reuse.
Instead of many separate variables, one object can group them.
Instead of random functions, methods stay with the thing they belong to.
That makes big programs easier to manage.
Quick check on methods
Which one is a method?
- color
- drive()
- Car
Show answer
drive(): Yes. drive() is a method because it is an action.
Two objects from one class
One class can make many objects.
Each object can have its own values, even if they come from the same class.
Your turn: instance or class?
In Python, is Dog a class or an object?
- Class
- Object
- Method
Show answer
Class: Right. Dog is usually the class name.
Remember the pattern
Use this checklist when you see classes and objects.
Class, then object, then properties and methods.
Last check
If you can point to the plan and the thing made from it, you already understand the core idea.
The class is the recipe.
The object is the cake.
Same recipe, many cakes.