Object class?


#1

Throughout the tutorials we're asked to make sure our classes inherit from the Object class but no explanation as to what's inside the object class is given besides "This means that our class has all the properties of an object, which is the simplest, most basic class"

What functionality does inheriting from the object class gives our class? What's inside it? What are its methods?
Is it possible to view it's methods somewhere?


#2

You can use dir(theobject) to get a list of a class' methods. By inheriting from the object superclass, you don't need to repeat the object's code every time you use an instance of the class.


#3

There are two types of classes in Python 2.2 and beyond and one type in Python 3.

If you make a class in Python 2 without inheriting from any class then you will create an old style class. To create a new style class you inherit from object (assuming it isn't inheriting from another class).

In python 3, you do not need to explicitly inherit from object as you can only create the new style classes.

If you want to know the differences in full, here it is from Guido van Rossum's mouth:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.