In programming languages, mainly there are two approaches that are used to write program or code.
The procedure we are following till now is the “Procedural Programming” approach.
So, in this session, we will learn about Object Oriented Programming (OOP).
The basic idea of object-oriented programming (OOP) in Python is to use classes and objects to represent real-world concepts and entities.
An object is an instance of a class, and it contains its own data and methods.
For example, you could create a class called "Person"
that has properties such as name
and age
, and methods such as speak()
and walk().
Each instance of the Person class would be a unique object with its own name and age, but they would all have the same methods to speak and walk.
A class is a blueprint or template for creating objects.
It defines the properties and methods that an object of that class will have.
Properties are the data or state of an object.
methods are the actions or behaviour that an object can perform.
One of the key features of OOP in Python is encapsulation,
which means that the internal state of an object is hidden and can only be accessed or modified through the object's methods.
Another key feature of OOP in Python is inheritance,
which allows new classes to be created that inherit the properties and methods of an existing class.
Polymorphism is also supported in Python,
which means that objects of different classes can be treated as if they were objects of a common class.
OOP in Python allows developers to model real-world concepts and entities using classes and objects, encapsulate data, reuse code through inheritance, and write more flexible code through polymorphism.