Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Operator overloading.py
#python 3.5.2 #Operator overloading(One operator having multiple forms) a=5#inbuilt 'int' object b=6 print(a+b)#internally int.__add__() gets called ,to add two int objects int class has inbuilt method __add__() #For every data type there is an inbuilt class defined which contais certain methods to process the objects or more precisely we can say to process the data #for example: #class int: #def __add__(self,x): #return self+x #def __sub__(self,x): #return self-x #def __mul__(self,x): #return self*x #These operators can be overloaded means one operator can have multiple forms defined #In python we have 2 inbuilt overloaded operators + and * # + is used for addition of two numbers and concatenation of two strings objects # * is used for multiplication of two numbers ond It can be used as a repeatation operator #Similarly we can overload the operators based on our requirement print(int.__add__(a,b)) a='2' b='3' print(a+b) print(str.__add__(a,b))
run
|
edit
|
history
|
help
0
PyWordQuant
Fig
binary_search
EJ2_PYTHON_20.321.212-7
sai exc 1
Moore Voting Algorithm
Your mom
HW Descending order
Hello World Test
9th jan quiz2