OOPs Concept in Python
OOPs in Python:
Object-oriented programming (OOPs) is a method of designing a program by binding there related properties and behaviours into individual objects. Here we will discuss, basics of object-oriented programming in Python.
For instance, an object could represent a Student with properties like a name, age, class, marks, stream etc.
- roll number
Principles of OOPs:
- Data Abstraction
- The class can be defined as a collection of objects. It is a logical entity that has some specific attributes and methods.
- We can also say that class is a blueprint of an object i.e. if any person is an object, class will have all the information about the structure or behaviour that person.
- OOPs, reduce the size of our code.
- Object is a simple entity which posses some property or behaviour.
- Everything in Python is an object, and almost everything has attributes and methods.
- 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 is the capability of one class to derive or inherit the properties from another class.
- The benefits of inheritance are:
- Reusability of code.
- We can use the features of the other class, without modifying it.
- It is transitive in nature i.e. A->B->C == A->C and B->C.
- The new class is known as derived class or child class.
- Polymorphism contains two words “poly” and “morphs”. Poly means many, and morph means shape.
- Polymorphism states that we can perform a task in more than one ways.
- There are two type of Polymorphism:
- Run-time Polymorphism
- Compile-Time Polymorphism
First Method 10
2nd Method: 10
- Data Abstraction is the process of hiding the real implementation of an application from a user and emphasizing only on usage of the application.
- We need data abstraction, so that programmer can hide irrelevant data and increase its efficiency.
- It is a process of wrapping of data, variable, and methods into a single entity in a program.
- Class is an example that wraps all the data.
- It is also used to restrict the access of data, variables, and methods.