Learning about the init method in Python

in #tech3 months ago

Hello friends,

PXL_20240908_062941751.PORTRAIT.jpg

I'm learning artificial intelligence and right now, one of the programming language I'm learning towards the field is, Python.
So today, I had to learn about the init method, and I was so excited about it such that I had to implement it on my calculator program and it went so well.

In object-oriented programming (OOP), classes help organize code into logical units, making it:

  1. Easier to understand
  2. Reusable
  3. Maintainable

Code


class Calculator:
def init(self):
self.result = 0

def add(self, num1, num2):
    self.result = num1 + num2
    return self.result

def subtract(self, num1, num2):
    self.result = num1 - num2
    return self.result

Feel free to use the code 😜
@princekeys

Posted using Bilpcoin