Hello friends,
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:
- Easier to understand
- Reusable
- 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