Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 12, 2022 10:31 am GMT

Python different between Function and OOP (class and object)

Function

def add(x, y):    return x + ydef multi(x, y):    return x * yprint(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.val2ob = do_match(2, 40)print(ob.multi())print(ob.add())

*Which one is easier and faster? *


Original Link: https://dev.to/phansivang/python-different-between-function-and-oop-class-and-object-1a46

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To