Sitemap
Harshini M

Harshini M

OBJECT ORIENTED CONCEPTS IN PYTHON

2 min readMay 9, 2022

--

In Python, object-oriented Programming (OOPs) is a programming paradigm that uses objects and classes in programming. It aims to implement real-world entities like inheritance, polymorphisms, encapsulation, etc. in the programming. The main concept of OOPs is to bind the data and the functions that work on that together as a single unit so that no other part of the code can access this data.

Main Concepts of Object-Oriented Programming (OOPs)

  • Class
  • Objects
  • Polymorphism
  • Encapsulation
  • Inheritance

CLASS:

A class is a collection of objects. Unlike the primitive data structures, classes are data structures that the user defines. They make the code more manageable. Let’s see how to define a class below-

class class_name:
class body

We define a class with a keyword “class” following the class_name and colon. And we consider everything you write under this after using indentation as its body.

Get Harshini M’s stories in your inbox

Join Medium for free to get updates from this writer.

OBJECT:

When we define a class only the description or a blueprint of the object is created. There is no memory allocation until we create its object. The objector instance contains real data or information. Instantiation is nothing but creating a new object/instance of a class. Let’s create the object of the above class we defined-

obj1 = flower()

POLYMORPHISM:

This is a Greek word. If we break the term Polymorphism, we get “poly”-many and “morph”-forms. So Polymorphism means having many forms. In OOP it refers to the functions having the same names but carrying different functionalities. It describes the concept wherein you can use different classes with the same interface. Each of these classes can provide its own implementation of the interface.

ENCAPSULATION:

In Object Oriented Programming, Encapsulation is defined as binding together the data and the functions that manipulates them. Encapsulation is used to hide the values or state of a structured data object inside a class, preventing direct access to them by clients in a way that could expose hidden implementation details or violate state invariance maintained by the methods.

INHERITENCE:

Inheritance is the procedure in which one class inherits the attributes and methods of another class. The class whose properties and methods are inherited is known as Parent class. And the class that inherits the properties from the parent class is the Child class. The interesting thing is, along with the inherited properties and methods, a child class can have its own properties and methods. How to inherit a parent class? Use the following syntax:

class parent_class:
body of parent class
class child_class( parent_class):
body of child class

These are some basic concept of oops in python.

--

--