Reputation:
There are different definitions for both which is really confusing.
Can someone please clarify the difference between them?
Upvotes: 7
Views: 5626
Reputation: 55924
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 is 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.
Upvotes: 6
Reputation: 386342
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.
Upvotes: 3