Function
def add(x, y):
return x + y
def multi(x, y):
return x * y
print(add(20, 200))
print(multi(22, 40))
Class and object (OOP)
class do_match:
def __init__(self, val1, val2):
self.val1 = val1
self.val2 = val2
def add(self):
return self.val1 + self.val2
def multi(self):
return self.val1 * self.val2
ob = do_match(2, 40)
print(ob.multi())
print(ob.add())
*Which one is easier and faster? *
Top comments (0)