12

I encountered a text saying:

... classes and objects ....

I was wondering what is the difference between objects and classes in python? I thought all classes are objects, but in that case, author wouldn't have used phrase "classes and objects".

1

5 Answers 5

13

These are two closely related terms in object oriented programming. The standard meaning is that an object is an instance of a class.

Sign up to request clarification or add additional context in comments.

Comments

8

An object is an instantiation of a class.

Think of a class like the blueprint of a car.

Ford make cars (objects) based on the rules and information enclosed in the blueprint.

2 Comments

and class is instantiation of what?
@Aleksey a class is an instantiation of a metaclass of course. Before you ask, a metaclass is also an instantiation of a metaclass and in Python terms the default metaclass 'type' is an instance of itself. i.e. type(type) is type
4

Yes, classes (and functions, and modules, and basically everything) in Python are objects, too. The difference lies in their types:

class Foo(object): pass
print type(Foo)
print type(Foo())

To see they're both objects, you can check that they both have attributes:

print dir(Foo)
print dir(Foo())

Comments

3

A class describes what that object will be, but it isn't the object itself.

Comments

2

A class is an idea. An object is the fruition of that idea.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.