On executing this code, I expected 0 but instead got [10]. The question is how does self work and should it be used while declaring variables local to a function within the class. In mod_a and mod_b both x.self is suppose to be local. The list is the result of the return in Line 4 or self.variable is a global variable declaration?
I have read the python documentation which refers to "this" of c++ but I don't know c++, therefore decided to ask here. Incase its been answered before please point me to it, I don't think I am using the right keywords in my search.
1 class ExampleClass(object):
2 def mod_a(self):
3 self.x=[10]
4 return self.x
5
6 def mod_b(self):
7 self.x=0
8 self.mod_a()
9 return self.x
10
11 if __name__=="__main__":
12 s=ExampleClass()
13 print s.mod_b()
Output
python test.py
[10]