Without self, it becomes indistinguishable from local variables (variables initialized inside the function).
class Sample:
num = 100
def show_num(self):
num = 200
print(self.num)
print(num)
a= Sample()
a.show_num()
The output is as follows
>>>100
>>>200
It means that there is a good distinction between print (self.num) and print (num).
Recommended Posts