Object Oriented Programming in Python, Python Object Oriented Programming, python oop, oop python

Hey peeps! Are you excited to begin with the new chapter in Python? Till now, we have been learning the data types and their related concepts. Now, we are starting a new chapter where you will learn the details of Object Oriented Programming or OOP. We are moving towards the advanced level of programming in Python, and here, you will go through the complex but interesting concepts that will show us the fascinating results on the screen. This will be more clear when you will know the basic information about the OOP, but before going deep, we will go through the headlines of the lecture:

  • How do you classify the programming languages?

  • How do you introduce the OOP?

  • Why object-oriented programming is important in Python?

  • How do you define class and objects in OOP and how are they connected?

  • What are polymorphism and encapsulation?

  • How do you use the inheritance in OOP?

  • How do you understand data abstraction in OOP?

  • What does method overloading mean?

Keep in mind, it is not a specific concept with Python but any higher-level programming language that supports the OOP has the same concepts and we are using a very general way to describe all the concepts.

Object Oriented Programming in Python, Python Object Oriented Programming, python oop, oop python

What does Type of Programming Language Mean?

Before going into the detail of this topic, it is helpful to understand why we are emphasizing on the OOP and its importance. Actually, there are different types of programming languages and being a programmer, you must know the basic categories. Some of the important types of programming languages are:

  • Procedural Programming Language

  • Functional Programming Language

  • Object-oriented Programming Language

  • Scripting Programming Language

  • Logic Programming Language


Out of which, we are interested in the OOP. The reason why the type of programming language is important, it describes the paradigm of the language, and therefore, we can understand the nature and the importance of that particular language in the profession you are using it for. Here, we should know what exactly the “paradigm” means:

“A programming paradigm is the concept to which a programming language's methodology adheres."

 Paradigms are significant because they define a programming language and its operation. The classification of the programming languages is done by keeping its paradigm in mind and in this way, the programmer may choose the type of programming language that exactly suits the application for which the coding is required.

Object Oriented Programming in Python, Python Object Oriented Programming, python oop, oop python

You can see that OOP comes in the imperative paradigm. In imperative programming, the user typically interacts directly with the computer's state, deciding how things should be calculated. In this way, more control is in the programmer’s hands, which is the basic source of attraction towards this programming language. In the practice of programming, I am sure you have touched other types of languages as well at any point. So, it becomes easy to compare and practice the code.

What is OOP in Python?

In real-time education, different types of subjects are taught to us by teachers. We are moving from basic to advanced programming in this course; therefore, we have covered the concept of data types before. This time, the OOP is our source of attraction, and we are going to learn it deeply because the programmers, most of the time, deal with the OOP when they are using the practical applications of the programming. Let us look at the introduction to the OOP:

“OOP (Object-Oriented programming) is a programming paradigm that organizes and structures code using objects and classes.”

For now, do not bother about the special terms used in this definition. We will learn a lot about them in these lectures with the help of different terminologies. Hence, if anything is causing confusion, do not worry because everything will be clear in just a bit. 

The concept of OOP is so vast and important that it is widely used to write powerful applications. The data engineers have to write these applications to access and use the data stored in different entities. 

The feature that makes the OOP unique is, it uses concepts that not only make the programming easy but efficient. It is based on the imperative programming paradigm, which employs statements to alter the state of a program. It is concerned with describing how a program should work. One must keep in mind that the main objective of the OOP is to bind the data and the functions of the program in such a way that all of these may work as a single unit but the security of the data remains intact. There are some important terms that you will see often in these lectures, so have a look at all of them.

  • Class

  • Objects

  • Polymorphism

  • Encapsulation

  • Inheritance

  • Data Abstraction

Keep in mind that you have to grasp the concept of each of these terms clearly so that, when you read them with other types of definitions, you may not be confused. You will learn all of these in detail in the coming lectures, but the basic introduction to all of them is given next:

Object Oriented Programming in Python, Python Object Oriented Programming, python oop, oop python

Class in OOP

Before going into the introduction of the OOP, one must know that an object is an instance of a class. Object and class are interconnected terms, and a class is defined as:

“In OOP, a class is a basic unit that represents the collection of objects, and it can be thought of as the blueprint or the prototype by following which, the objects are made.”

The attributes of a particular thing, connected with each other, can be represented with the help of the class, where the number of the attributes starts at one and can be two, ten, or any other positive number. In this way, a simple and basic class can be used to store all types of physical or logical information about a particular product. 

Objects in OOP

In object-oriented programming, objects are the basic units of data. An object is associated with the class and is the entity with which the state and behaviour of the class are associated. If it is confusing at this point, do not worry because we are going to discuss the object in detail and will work again and again with the objects.

The good thing about the objects in OOP is that, just like the real-time concept of objects, the programming objects may be anything, whether it is physical, such as a car, an animal, a plant, a cooking item, any food, or any other thing, or abstract, such as any software, a bank account, a soft blueprint, or any document. The positive thing about the object is, it allows us to reuse the same code anywhere in any block of the same code where the same attribute of the object is to be used.

Polymorphism in OOP

The fundamental concept of the OOP is polymorphism, and it has the same features as the family in real life. To keep things simple, we assume that all the objects belong to the same class, and the polymorphism allows us to use the objects together as they are from the same family. In this way, the same objects can be used interchangeably in the same context. In this way, the workload of the programmer is minimized as much as possible through polymorphism. In simple words, the concept of polymorphism is the same as it is in chemistry, where the same element can be used in different ways when certain conditions are met.

Object Oriented Programming in Python, Python Object Oriented Programming, python oop, oop python

Another feature that makes the polymorphism attractive is the availability of the alteration in the classes, both in terms of their size and the data stored in them. All this information will be cleared up in the coming lectures, but for now, we only understand the basics of polymorphism. In other words, we all know that poly means "many,” and if we talk about OOP, it includes the concept of a class's ability to get the features of already existing classes in this way. For example, you can assign the attributes of a particular product, such as a car, to another car with the same basic features but with different attributes. This is just a basic example of polymorphism, and many people mix this concept with inheritance, but these are different, and you will learn a lot about them in the next lectures.

Encapsulation in OOP

The next concept that we are going to discuss is encapsulation, and to make your concept clear, let us take the example of the capsules that we get from the pharmacy for different health issues. These capsules protect the inner medicine, and the same concept can be applied to this type of encapsulation to reinforce the concept. Basically, the data is protected with the help of different concepts used in the encapsulation.

Object Oriented Programming in Python, Python Object Oriented Programming, python oop, oop python

The programmers are very sensitive about their codes and the data stored with the help of these codes. Encapsulation is used to give the code privacy and protect it from unwanted users. The private attributes of the code that are enclosed in the capsule are only accessible by the programmer itself. In other words, we cannot use the private attribute in other blocks of code until the programmer himself allows it. 

Inheritance in OOP

Another important feature of the OOP is inheritance, and this is the point where we can say that the OOP is making Python more effective and easier to use. It is one of the most significant points of the OOP, and with the help of easy and effective Python, programmers can inherit the characteristics and attributes of any class and assign them directly to others. For this, you have to learn about the child and parent classes, but for now, we are leaving this topic here and moving on to the next point that will show us the importance of the OOP, especially when we use it in Python. 

Data Abstraction in OOP

If you are interested in becoming a professional programmer, then some points should always be kept in mind, and the most important one is to always go with clean code that precisely describes the code and gives the exact coding without any errors. For this, some concepts will help you a lot, and one of them is the concept of data abstraction. With the help of this concept, the programmer is able to code cleaner because "data abstraction" means writing cleaner code and hiding unnecessary details from the users. It is yet another method for the programmer to maintain privacy from the end user. THE SENSITIVE CODES ARE HIDDEN FROM THE OTHER USERS USING DIFFERENT TECHNIQUES. The whole process of data abstraction revolved around making and implementing the abstraction classes and then calling them in different ways according to the requirements of the code.

Object Oriented Programming in Python, Python Object Oriented Programming, python oop, oop python

Method Overloading in Python

Here is a small topic to be discussed that is not a particular part of OOP in Python, but almost every programming language that works with OOP has it. This is also true for other characteristics that we have discussed so far. 

In method overloading, many methods with the same name are declared and then called at once. In this way, a single class can take multiple arguments. Other concepts, such as method overriding, are also connected with the same concept, and we will discuss them with some suitable examples. 

Consequently, we have almost all the basics of the OOP. We have read a lot about them and tried to make them more general so that the programmers working on them other than Python may also get the useful concepts from this lecture. Actually, the OOP is not just confined to Python, but we have to connect it with Python, and this will be more fully discussed in the next lectures, where all these concepts will not only be discussed but the practical implementation of codes will help us to have a grip on Python. This is an extremely useful topic and therefore, we will move a little bit slowly on these lectures and will understand each and every point in detail.