Object-Oriented Programming (OOP) is a programming paradigm that revolves around the concept of "objects," which are instances of classes.
Python supports object-oriented programming from its beginning. since Python is object-oriented it helps in creating object and classes.
an object is a blueprint of class, we can relate it to real-world entities such as cars, mobiles, laptops, tables, etc. The oops concept helps in writing reusable code.
Python supports OOP principles and provides features like classes, objects, inheritance, encapsulation, and polymorphism.
Here's an overview of OOP concepts in Python:
Class
Object
Inheritance
Polymorphism
Abstraction
Encapsulation
A class is a blueprint for creating objects.
It defines the properties (attributes) and behaviours (methods) that all objects of that class will have.
In Python, we can define a class using the "class" keyword.
class YourClassName: <statement>
An object is an instance of a class.
class YourClassName: <statement> yourClassObj = YourClassName()
It represents a real-world entity that has attributes and behaviours defined by its class.
Inheritance allows a class (subclass) to inherit attributes and methods from another class (superclass).
It promotes code reusability and supports the concept of "is-a" relationships.
Encapsulation is the bundling of data (attributes) and methods that operate on that data within a single unit (class).
It hides the internal state of objects from the outside world and only exposes necessary interfaces.
Polymorphism helps us to perform one task in different ways.
Polymorphism allows objects of different classes to be treated as objects of a common superclass.
It enables flexibility in method implementation and supports the concept of "one interface, multiple implementations."
Python allows us to create abstract base classes.
Abstract base classes are classes that cannot be instantiated directly but can be subclassed.
They define abstract methods that must be implemented by concrete subclasses.