Reputation: 483
I started learning Python and got stuck at classes (with no prior programming background or knowledge).
Is an "object" a synonym for "an instance of the class"?
Thank you.
Upvotes: 1
Views: 2590
Reputation: 6111
Yes, and by the way everything in Python is an object.
Here goes pretty good explanation in Dive Into Python.
In addition, here is the link to pretty good video... It might be a little overwhelming for novice user. However, "everything is an object" explanation is pretty good: Python Epiphanies
Upvotes: 1
Reputation: 309929
depends. Typically, I would say no. object
is the base class of all new style classes (all classes in python3.x):
class Foo(object):
...
As such, I would say that object
is more the most basic type of most class instances. So, if I create a Foo
:
f = Foo()
print isinstance(f,object) #True
We see that f is an instance of the object type.
However, there are a lot of informal terms which get thrown around and object
is one of them. In some contexts, you'll see people saying that 'anything is an object'. Basically what they mean by that is that you can assign anything to a new name:
bar = Foo #Now bar is an "alias" for Foo.
We can do this assignment because Foo
is an "object" (lazy vernacular).
Upvotes: 7