Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # define class
- class Calc:
- def __init__(self, a, b):
- self.x = a
- self.y = b
- def add(self):
- return self.x + self.y
- def sub(self):
- return self.x - self.y
- def mul(self):
- return self.x * self.y
- def div(self):
- return self.x / self.y
- # create instance
- my_calc = Calc(6, 3)
- # use methods of instance
- print(my_calc.add()) # 9
- print(my_calc.sub()) # 3
- print(my_calc.mul()) # 18
- print(my_calc.div()) # 2
Add Comment
Please, Sign In to add comment