Blue Week Special Offer | Brighten your week!
days
hours
minutes
seconds

Object vs Instance

Object-Oriented Python For Data Science | Dataquest

I am confused on the difference between an object and an instance. I understood an object to be similar to a variable. Is an instance an example of an object within a class? Or simply the description of an object?

In general I find the definitions within object-oriented programming quite difficult to grasp.

Thanks in advance for any help

This is the primary example/analogy used in the content -

here are hundreds of thousands of Tesla cars around the world. Each car is similar in that it is a Tesla — it’s not a Ford or Toyota — but at the same time, it is not necessarily identical to other Teslas. We would say that each of the cars are objects that belong to the Tesla class.

As it states,

  • Tesla would be a class.
  • The Tesla cars are objects belonging to the Tesla class

Then, they explain an instance -

we use instance to describe each different object.
These cars are two instances of the Tesla class

So, based on all of the above, we have -

  • Tesla would be a class.
  • The Tesla cars are objects belonging to the Tesla class
    • Each object is an instance of the Tesla class.

Now, looking at the above, you get the question you asked -

what’s the relation between an object and an instance?

For the time being, I would suggest that you consider them to be similar for the sake of simplicity.

There is some additional technical knowledge that would make a distinction between the two, but, in Python, for now, you can consider them to be similar.

But, do focus on the statement itself -

An object is an instance of a class

and the associated word - instantiate.

We instantiate an object of a class.

1 Like

thank you for this prompt reply, it is clearer to me now.