Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 3, 2020
Embed
What would you like to do?
class Student:
def __init__(self,a,b):
self.a=a
self.b=b
def __str__(self):
return "{},{}".format(self.a,self.b)
def __iadd__(self,other):
self.a+=other.a
self.b+=other.b
return Student(self.a,self.b)
def __isub__(self,other):
self.a-=other.a
self.b-=other.b
return Student(self.a,self.b)
def __imul__(self,other):
self.a*=other.a
self.b*=other.b
return Student(self.a,self.b)
def __itruediv__(self,other):
self.a/=other.a
self.b/=other.b
return Student(self.a,self.b)
def __ifloordiv__(self,other):
self.a//=other.a
self.b//=other.b
return Student(self.a,self.b)
def __imod__(self,other):
self.a%=other.a
self.b%=other.b
return Student(self.a,self.b)
def __ipow__(self,other):
self.a**=other.a
self.b**=other.b
return Student(self.a,self.b)
def __ilshift__(self,other):
self.a<<=other.a
self.b<<=other.b
return Student(self.a,self.b)
def __irshift__(self,other):
self.a>>=other.a
self.b>>=other.b
return Student(self.a,self.b)
def __iand__(self,other):
self.a&=other.a
self.b&=other.b
return Student(self.a,self.b)
def __ixor__(self,other):
self.a^=other.a
self.b^=other.b
return Student(self.a,self.b)
def __ior__(self,other):
self.a|=other.a
self.b|=other.b
return Student(self.a,self.b)
# Instantiating two Student Objects
s1=Student(15,25)
s2=Student(3,5)
#performing Arithmetic assignment += on two objects. Magic method __iadd__(self,other) is invoked.
s1+=s2
print (s1)#Output:18,30
#performing Arithmetic assignment -= on two objects. Magic method __isub__(self,other) is invoked.
s1-=s2
print (s1) #Output:15,25
#performing Arithmetic assignment *= on two objects. Magic method __imul__(self,other) is invoked.
s1*=s2
print (s1)#Output:45,125
#performing Arithmetic assignment <<= on two objects. Magic method __ilshift__(self,other) is invoked.
s1<<=s2
print (s1)#Output:360,4000
#performing Arithmetic assignment >>= on two objects. Magic method __irshift__(self,other) is invoked.
s1>>=s2
print (s1)#Output:45,125
#performing Arithmetic assignment &= on two objects. Magic method __iand__(self,other) is invoked.
s1&=s2
print (s1)#Output:1,5
#performing Arithmetic assignment ^= on two objects. Magic method __ixor__(self,other) is invoked.
s1^=s2
print (s1)#Output:2,0
#performing Arithmetic assignment |= on two objects. Magic method __ior__(self,other) is invoked.
s1|=s2
print (s1)#Output:3,5
#performing Arithmetic assignment /= on two objects. Magic method __itruediv__(self,other) is invoked.
s1/=s2
print (s1)#Output:1.0,1.0
#performing Arithmetic assignment //= on two objects. Magic method __ifloordiv__(self,other) is invoked.
s1//=s2
print (s1)#Output:0.0,0.0
#performing Arithmetic assignment %= on two objects. Magic method __imod__(self,other) is invoked.
s1%=s2
print (s1)#Output:0.0,0.0
#performing Arithmetic assignment **= on two objects. Magic method __ipow__(self,other) is invoked.
s1**=s2
print (s1)#Output:0.0,0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment