Python OOP

Welcome to the new part of programming : Object Oriented Programming (OOP)

Wait for a while. You came up till here. Have you celebrated this? If not, then go and take a break, because you have achieved a milestone in programming. Believe us!

Now after your break, let's talk about Object Oriented Programming.

To understand Object Oriented Programming, think of a book having a serial number and a number specifying the number of pages in the book. Now, suppose you have two types of books - Science book and Computer book. Suppose the serial number of the Science book is SC12 and that of the Computer book is CS34 and the number of pages are 200 and 250 respectively. It is like in the picture below:

Object oriented programming in Python

Here, ‘Book’ is a class having attributes 'Page' and 'Serial number', and 'Science' and 'Computer' are objects(instances) of ‘Book’.

So, now you understand that class is something which acts like a base, having some attributes or features(Page and Serial Number in this case). And objects are instances of class following those definitions.

One more example of class and objects you can think of is a bank account. Think of 'Account' as a class having attributes 'min_balance' and 'rate_of_interest', and 'Saving' and 'Current' as its objects.

Object oriented programming in Python

I hope you have got the feel of classes and objects. We will be programming this in the next chapter.

I’ve failed over and over and over again in my life and that is why I succeed.
- Michael Jordan

Doubt? Ask question