Like other modern programming languages, Python is also an object-oriented programming (OOP) language. Oops is a modern concept to solve a problem by creating an object and a class. There are some features of an object-oriented programming language such as Object, Class, Inheritance, Abstraction, Polymorphism, and Encapsulation. We will discuss these features of oops step by step. We will also learn how to create class and object in Python.
Python Object
An Object is a real-life entity, which has some attributes and behaviours. Entity means everything which exists, attributes of the object mean identity of an object and behaviour mean functions of the object. We can also define the object as an instance of a class.
Python Class
The class is blueprint or template which is used to define attributes and behaviour of an object. It means, all the attributes and behaviours of the object is defined in a class.
For example car is a class, BMW is an object of car class, color of the BMW car is attribute and speed of the car is behavior.
Inheritance
Inheritance is a concept, in which we can create a new class based upon the existing class. The new class is called sub, derived or child class and the existing class is called the base, super or parent class. The new class can inherit members of an existing class in it.
For example, Transport is a parent class, and Car is a child class based on Transport class.
Encapsulation
Wrapping of different data members(attribute and behaviour) in a single unit is known as encapsulation. In oops concept, all the variables(attributes) and functions(behaviours) are the part of the class.
For example sound system, display unit and control unit of tv is wrapped in a single unit(cabinet).
Abstraction
Hiding of internal details which are required for the object but not for outside the world is known as abstraction.
For example, engine of the car is important part of the car but not for the world. Steering and brake of the car is for outside the world. Hiding the engine and show the steering to the world is abstraction.
Polymorphism
Polymorphism is a concept, in which a function can redefine in different ways.
For example speed of different transport can be defined dieffrent. Speed of the Car and the Aeroplane is different.