In the example below, classes AA and BB are instantiated with params a and b and feature the foo method. The only difference between classes AA and BB is that in the AA foo method, the intermediate variable z is prefixed with the class instance reference self while in class BB it is not. What is the correct methodology here? When should self be used within class methods and when should it not be used? I've always been confused by this!
class AA:
def __init__(self, a, b):
self.a = a
self.b = b
def foo(self):
self.z = self.a + self.b
return self.z * self.a
class BB:
def __init__(self, a, b):
self.a = a
self.b = b
def foo(self):
z = self.a + self.b
return z * self.a