Introduction
Languages that use objects in programming are called Object Oriented Programming. Everything in Python is an Object.
Object is an abstract data type. An object has two characteristics:
- Attributes
- Behaviour
Let us take an example, Child is an object. Its characteristics are: Name, Age, Blood Group, Caste etc. Attributes are: Crying, Dancing, Playing, Studying etc. (Behaviour)
Oops Concepts in Python
Class
The class is a blueprint that defines a nature of a future object. A class is collection of objects
- class MyClass(): //Creating a class
- "This is a DocString"
- x = 5
- MyClass = MyClass()
- print(MyClass) // output: __main__.MyClass object at 0x00000138B2138508>
- print(MyClass.x) // output: 5
- print(MyClass.__doc__) //output: This is a DocString
Object
An instance is a specific object created from a particular class.
- class MyClass():
- x = 5
- def myFunction():
- print('Hello')
- my_object = MyClass() //Creating an object of a class
- print(my_object.x) //output: 5
- print(MyClass.myFunction) //output: <function MyClass.myFunction at 0x0000025AC1D43678>
- print(my_object.myFunction) //output: <bound method MyClass.myFunction of <__main__.MyClass object at 0x000001B69C068488>
Relationship between a Class and an Object

In this Example, the Class is Human, i.e a logical entity with some attributes and methods for example: hair, nose, legs, arms etc. And; Object is an entity that has state and behavior. So here, In class Human, we have Objects like man, woman and child, they may have some state and behaviour such as, sleeping, eating etc.
Polymorphism
Poly means many Morphism means forms. In Polymorphism, the functions are of same name but their functionalities are different.
For Example: (In-Built Polymorphism)
- print(len("Aashina")) //output:7
- print(len([1, 2, 3])) //output:3
Let us see another example of Polymorphism ( User-Defined Polymorphism)
- class Jasmine():
- def color(self):
- print("Jasmine flower comes in white, pink, blue, orange, yellow, purple, and red color")
- def scientific_name(self):
- print("Jasminum sambac is scientific name of Jasmine")
- def family(self):
- print("Jasmine is from Oleaceae family")
- class Lily():
- def color(self):
- print("Lilies commonly grow in white, yellow, pink, red, and orange color.")
- def scientific_name(self):
- print("Lilium is scientific name of Lily")
- def family(self):
- print("Lily is from Liliaceae family")
- obj_jasmine = Jasmine()
- obj_lily = Lily()
- for flower in (obj_jasmine, obj_lily):
- flower.color()
- flower.scientific_name()
- flower.family()

Inheritance
By using inheritance, we can create a class which uses all the properties and behaviour of another class. In Inheritance we have a parent and a child class, as in real life a child inherits the characteristics of his/her parents, likewise, child class have properties of the parent class.



Judi Adu Ayam RknslotPosted Apr 6, 2020, 5:47 AM
Nice article
Onkar SharmaPosted Nov 6, 2019, 10:45 PM
Nice article, very well explained the OOPs Concept...
Sanjit Kumar SinghPosted Nov 6, 2019, 4:38 PM
Nice article