What is the difference between an instance and an object in Python?

Viewed 1482

I know that this question has been asked and answered many times but the answers to those questions aren't really assuaging. Each person has given a different definition of both which is really confusing. Being a novice, I really don't know whom to trust. Can someone please clarify the difference between them?

2 Answers

In Python, everything is an object. Moreover in Python objects are instances of classes, so it follows that every object is also an instance of some class*.

However, we generally use the term instance in preference to object when we want to discuss the behaviour of instances of a specific class or classes

Instances of Foo provide the following operations ...

No two instances of Bar may compare as equal ...

So we might say that object is the most general term, whereas instances refers to the set of objects which are instances of a particular class or classes, and instance to a specific object which is an instance of a particular class.

In short, they are the same thing, but we use these terms in different contexts.

*Python enables this circular definition by making object an instance of type, and type an instance of object, and both object and type are instances of themselves.

instance and object are effectively the same thing. When you create an instance of a class, that instance is an object.

Put another way, every instance is an object. That is the literal definition of an object: an instance of a class.

Related