डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

Full Stack Web Development with Laravel

Full Stack Web Development with Laravel

Affiliate Program

Affiliate Program

Python polymorphism

Polymorphism means many form. in python there are many operators and function which have many forms.
it is useful to create different classes and having a functions with same name, that helps to re-use of of code which decrease lot of complexity in programming.

Polymorphism in operators.

+ operator calcualate addition of two number and concat two string.
print("aman" + "singh")

Polymorphism in functions

marks=[12, 34, 45, 56]


In compostion, one of the classes is composed of one or more instance of other classes, in this concept one class is like a container and other one is a content, when you delete a container object, then relatively all content objects deleted also.

Python overloading

When python operator have different meaning according to the context is called operator overloading.
For example + operators is used to calculate sum of two number and concat two string.

Python special functions

Function in a class beign and end with double underscore __function_name__ are called special functions.
p1+p1 p1.__add__(p2)
p1-p2 p1.__sub__(p2)
p1*p2 p1.__mul__(p2)
p1**p1 p1.__pow__(p2)
p1/p2 p1.__truediv__(p2)
p1//p2 p1.__floordiv__(p2)
p1%p2 p1.__mod__(p2)
p1<p2 p1.__lt__(p2)
p1<=p2 p1.__le__(p2)
p1>p2 p1.__gt__(p2)
p1>=p2 p1.__ge__(p2)
p1==p2 p1.__eq__(p2)
p1!=p2 p1.__ne__(p2)

Method overriding

When a method in a subclass has same name, parameters, and same return type as a super class method, the method in the sub class is called override method.
In OOP, Method overriding is an ability to allow sub class to implement specific 
© 2016 - 2023, All Rights are Reserved.