Lesson - 50 : Python Advanced - Python OOP’s : Operator Overloading

Veröffentlicht am: 09 Januar 2018
auf dem Kanal: Sada Learning Hub
207
2

**************************************************
Python Core PlayList :    • Lesson - 01 : Python3 - What is python  
Python Advanced PlayList :    • Lesson - 46 : Python Advanced - Pytho...  
**************************************************

Python OOP’s : Operator Overloading:

You have already seen you can use +  operator for adding numbers and at the same time to concatenate strings. It is possible because +  operator is overloaded by both int  class andstr  class. The operators are actually methods defined in respective classes. Defining methods for operators is known as operator overloading. For e.g. To use +  operator with custom objects  you need to define a method called _add_  .

Operator Function Method Description
__add__(self,other) Addition
__mul__(self,other) Multiplication
__sub__(self,other) Subtraction
% __mod__(self,other) Remainder
/ __truediv__(self,other) Division
< __lt__(self,other) Less than
<= __le__(self,other) Less than or equal to
== __eq__(self,other) Equal to
!= __ne__(self,other) Not equal to
> __gt__(self,other) Grater than
>= __ge__(self,other) Grater than or equal to
[index] __getitem__(self,other) index operator
in __contains__(self,other)check membership
len __len__(self,other) The number of elements
str __str__(self,other) The string representation

Sample Projects : https://github.com/SadaLearningHub1/P...


Auf dieser Seite können Sie das Online-Video Lesson - 50 : Python Advanced - Python OOP’s : Operator Overloading mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Sada Learning Hub 09 Januar 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 207 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!