Introduction to Object oriented programming in Python
In this lesson, you will learn about Object-Oriented Programming aka OOPs concepts in python
Introduction to Object-Oriented Programming in Python
When a programming language uses objects and classes, it is called an object-oriented programming language. Python does support different programming methods and it does use objects and classes in high-level concepts making it an object-oriented programming language. The need for binding functions and data that performs a particular task multiple times without any interference from the rest of the code paved the way for the Oops concepts.
Main Concepts of Object-Oriented Programming (OOPs)
A class is a collection of objects and attributes with methods. They are created using the keyword Class in python.
class ClassName: # Statement-1 . # Statement-N
The object is an entity that has a specific behaviour and properties. Integers, strings, floating-point numbers, even arrays, and dictionaries, are all objects. It interacts with other objects in a code and performs the specified tasks.
obj = Add()
If a class can inherit the properties and capabilities of another class, then it is called inheritance. The class that inherits is called the derived class or child class and the class from which it inherits is called the base class or parent class. It helps in the reusability of a code.
Polymorphism is the use of a single attribute in different y forms. Using polymorphism we can solve many complex problems in real-world applications.
As the word Encapsulation means, it is the method of binding different types of data, method into a single entity. It is the prime or basic concept of object-oriented programming (OOP). It helps in preventing unwanted access and manipulation of data. To change the data inside the encapsulated entity, you should use the object’s method. Variables used in the object’s method are known as private variables.
Example of encapsulation Class()