""" depends on the data type too """
def callme(key1, key2):
print(key1, key2)
obj1 ,obj2 = 6, 9
obj3 = {
"key1": 1,
"key2": 2
}
callme(**obj3) # easy for calling functions
print(obj1 ** obj2) # Here it is a operator (for calculating obj1 ^ obj2)
# @ is used for matris multiplication
class Mat(list):
def __matmul__(self, B):
A = self
return Mat([[sum(A[i][k]*B[k][j] for k in range(len(B)))
for j in range(len(B[0])) ] for i in range(len(A))])
A = Mat([[1,3],[7,5]])
B = Mat([[6,8],[4,2]])
print(A @ B)
>>> class Adder(object):
def __init__(self, num=0):
self.num = num
def __iadd__(self, other):
print 'in __iadd__', other
self.num = self.num + other
return self.num
>>> a = Adder(2)
>>> a += 3
in __iadd__ 3
>>> a
5
""" depends on the data type too """
def callme(key1, key2):
print(key1, key2)
obj1 ,obj2 = 6, 9
obj3 = {
"key1": 1,
"key2": 2
}
callme(**obj3) # easy for calling functions
print(obj1 ** obj2) # Here it is a operator (for calculating obj1 ^ obj2)
# @ is used for matris multiplication
class Mat(list):
def __matmul__(self, B):
A = self
return Mat([[sum(A[i][k]*B[k][j] for k in range(len(B)))
for j in range(len(B[0])) ] for i in range(len(A))])
A = Mat([[1,3],[7,5]])
B = Mat([[6,8],[4,2]])
print(A @ B)
>>> class Adder(object):
def __init__(self, num=0):
self.num = num
def __iadd__(self, other):
print 'in __iadd__', other
self.num = self.num + other
return self.num
>>> a = Adder(2)
>>> a += 3
in __iadd__ 3
>>> a
5