Alex Rivera | Logout

Objects vs instance in python

Asked 2011-06-16T07:23:40.723
13

In C++ there are just objects and classes, where objects are instances of classes.

In Python, a class definition (i.e., the body of a class) is called an object. And, the object in C++ is called instance in python.

Check this

Am I wrong?

EDIT : Actually can someone explain with example difference of object vs instance

EDIT : In python, everything will inherit from object class & hence everything is an object (i.e object of object class).

A Class is also an object (i.e object of object class).

Instance is the name used to call the object of any class.(a.k.a c++ object).

Please refer this

Edit
Report

1 Answer

9

Terminology-wise, classes and instances are both called objects in Python, but for you as a regular Python programmer this is of no importance. You can see Python's classes and instances pretty much as C++'s classes and instances:

class MyClass:
  data = 1

mc = MyClass()

MyClass is a class and mc is an instance of class MyClass.


Python is much more dynamic in nature than C++ though, so its classes are also objects. But this isn't something programmers usually are exposed to, so you can just not worry about it.

answered 2011-06-16T07:26:38.387

Your Answer