Discussion Forum | Board Infinity

What is the oops concept?

Oops Concept in Python

Python has also been an object-oriented language since its beginning. Python is an object-oriented programming language. It allows us to develop applications using an Object-Oriented approach. In Python, we can easily create and use classes and objects.

Major principles of object-oriented programming systems are given below.

  • Object:- The object is an entity that has state and behavior. It may be any real-world object like the mouse, keyboard, chair, table, pen, etc.

  • Class:- The class can be defined as a collection of objects. It is a logical entity that has some specific attributes and methods. For example: if you have an employee class then it should contain an attribute and method, i.e. an email id, name, age, salary, etc.

  • Method:- The method is a function that is associated with an object. In Python, a method is not unique to class instances. Any object type can have methods.

  • Inheritance

  • Polymorphism:- Polymorphism contains two words “poly” and “morphs”. Poly means many and Morphs means form, shape. By polymorphism, we understand that one task can be performed in different ways. For example You have a class animal, and all animals speak. But they speak differently. Here, the “speak” behavior is polymorphic in the sense and depends on the animal. So, the abstract “animal” concept does not actually “speak”, but specific animals (like dogs and cats) have a concrete implementation of the action “speak”.

  • Data Abstraction:- Data abstraction and encapsulation both are often used as synonyms. Both are nearly synonyms because data abstraction is achieved through encapsulation.

  • Abstraction is used to hide internal details and show only functionalities. Abstracting something means to give names to things so that the name captures the core of what a function or a whole program does.

  • Encapsulation:- Encapsulation is also an important aspect of object-oriented programming. It is used to restrict access to methods and variables. In encapsulation, code and data are wrapped together within a single unit from being modified by accident.