An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 12, 2022 10:31 am GMT
Original Link: https://dev.to/phansivang/python-different-between-function-and-oop-class-and-object-1a46
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:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To