17.12.2019 06:27

OOPs Concepts in Python

OOPs Concepts in Python

OOPS:

Python develops applications, with the help of Object-Oriented Programming concepts(OOPs). Object-Oriented Programming in Python is a programming model, which gives structured programs so that behaviors and properties, are tied together into single objects.

Object-Oriented Programming is a way of creating strong, real-time things like cars and connected things, like teachers and students, etc. OOP represents real-time things as software objects, that have data related to them and can do specific functions.

Object-Oriented Programming concepts include concepts of class, object, method, inheritance, polymorphism, data abstraction, and encapsulation.

To get in-depth knowledge on Python You can enroll for free live demo Python Online Course

Class:

For instance, if you want to find a number of different animals. If you used a list or an array, the first component can be the name of the animal, and the second component may be its age.

But from this, how can we know which component is meant to be what? If you have 200 various animals? Are you sure every animal has both, age and name? To these animals, if you want to add other properties? For this, the Organization of data is a drawback, so we use classes.

Class is used to make a data structure, defined by users that has some information about something. Take the animal example, to record the properties of an animal like the age and name, we create a class animal().

Class is the plan for defining anything, but it doesn’t show us any real matter. In the animal() class, the age and name are required to define an animal, but it will not mention a certain animal’s age or name.

Learn For Python programming

Object or instances:

An Object is a duplicate of the class, with real values. The object is a substance that has behavior or functions and state. The object can be any real-time substance like a car, pen, etc. like a cat named kitty whose age is 6 years.

A class is similar to a form, which specifies the required data. When you complete filling the form, your form is an example of the class and it has real data of you.

Method:

The method is a function of an object, which is defined inside a class. Methods are used to define, the function or behavior of an object.

Inheritance:

Inheritance is the major concept of OOP that uses the real-time inheritance concept. This means that the child objects use, all the behaviors and properties of the parent object. The inheritance concept can be used to reuse the code.

With the help of the Inheritance concept, we can create a class that can use all the behavior and properties, of some other class. The class that we created is known as, child class or derived class whereas, the class whose properties are being used is known as, Parent class or base class.

Polymorphism:

Poly indicates many and morphs indicate shapes or forms. By the name, we can say by using Polymorphism concept, we can perform one task in many ways.

For instance, if you have an animal class, and every animal speak. But each animal speaks in various ways. In this example, the behavior, speaking is polymorphic and it is based on animals. Generally, animals don’t speak but some certain animals like, cats and dogs have a strong application.

Data Abstraction:

By using the Abstraction concept, we can hide inner data and can show only activities. Abstracting means giving names, to things so that the name contains the details of the function or program.

Generally, Encapsulation and Data abstraction are used as a synonym because data abstraction is done, with the help of encapsulation.

Learn Python Interview questions

Encapsulation:

Encapsulation is an important concept in OOP. By using the Encapsulation concept, access to variables and methods can be restricted. Data and programs are covered together in one unit, in Encapsulation so that it can’t be modified by chance.

In python, we define a private attribute with the help of underscore as a prefix.

By using OOPs concepts in python, we can achieve the following:

With the help of the data abstraction concept, the data is secure and safe.

Classes can be shared, we can reuse the code.

The coding is effective and easy.

The efficiency of the programmer increases.

In this article, I have explained about OOPs concepts in python. I will explain about reading JSON in python topic in my next article.

Text je súčasťou Refresher Blogu, nie je redakčným obsahom. Administrátorov môžete kontaktovať na [email protected].

Ohodnoť blog
0
Poslať správu
AWS training and certification course masters you in AWS cloud, IAM, Lambda, Redshift, EC2, S3, cloud trail and more. You will work on various tools of AWS cloud platform and create SaaS applications that are highly scalable, highly available and fault-tolerant. Learn for more AWS Online training

Chceš vedieť, keď narayana pridá nový blog?

Zadaj svoj mail a dostaneš upozornenie. Kedykoľvek sa môžeš odhlásiť.