Python is a very object-oriented language, which makes it easy to work with. For those of you who may not be familiar with the concept of object-oriented programming languages, Peyton provides a complete, easy-to-understand explanation, and then gives a number of examples that illustrate how object orientation works in Python.
It seems that everywhere you go, you hear the term "object orientation" in relation to programming. However, it is a concept that many newcomers don't understand, especially if they are starting in languages that feature little or no object orientation.
In this article, we'll take a look at what object orientation is, the benefits it provides programmers and its impact on the programming community.
Object Orientation 101
Before we talk about what object orientation is, let's talk about what object orientation isn't. Object orientation isn't a simple string spat out sending a greeting to the world. Object orientation isn't a variable modified by an external function, either. Think of a basic variable in, say, PHP. It's just a container and nothing more. It doesn't have a shape. It doesn't have mass. It doesn't have a color. It's just a void. (I have nothing against PHP, by the way, and I am aware that PHP is indeed object-oriented to an extent. This is merely an example.)
Now we'll dive into what object orientation is. Object orientation is all about, obviously, objects. These objects have their own data and their own methods that act on the data. For example, let's look this code:
aFile = open ( 'someFile.txt', 'w' )
The variable aFile is an object. Why? First of all, it has its own attributes which describe it:
It also has its own methods. Methods are similar to functions, but they belong to objects and perform actions to the object's data: