Defining a Class

Below we define a simple class called MathOperations that will contain some basic math methods

class MathOperations:

    def __init__(self, x_value, y_value):
        self.x = x_value
        self.y = y_value

    def add(self):
        return self.x + self.y

    def subtract(self):
        return self.x - self.y

Using the Class

To use the class, we must initialize the values defined in the __init__ method as seen below:

calculator = MathOperations( 3, 5)
calculator.add(), calculator.subtract()

(8, -2)