In this lecture, we start talking about object oriented programming, which is a way of programming by abstracting things we manipulate in a program as objects.
An object is a bundle of data and methods that handle the data.
In Python, everything is an object.
In fact, object
is a type in the Python language.
You can create a new object using the object()
function.
>>> o = object() >>> type(o) <type 'object'>
A function whose name is a type’s name and whose purpose is to create an object of that type is called a constructor.
As before, you can see what methods are contained in the object by using the dir
function.
The fact that everything in Python is an object means that everything inherits from object
. We will talk about inheritance in the next lecture, however.