Is there any difference between a self.var and a var in a class? for example:
class nameClass:
def names(self):
self.name1 = "aaaa"
name2 = "bbbb"
def printNames(self):
print self.name1
print name2
now if I instantiate the class and I want to use the name2 variable, and it doesn't let me.
obj1 = nameClass()
obj.printNames()
it will print the name1 but for the name2 it says:
NameError: global name 'name2' is not defined
so I assume for variables which we use just inside a method it is better to not use 'self' but for other variables that we want to modify later or pass them to the other methods it is better to use 'self'.
Is there any other difference?!