Possible Duplicate:
Why do you need explicitly have the “self” argument into a Python method?
In Python, instance variables must be accessed via self.x
, but global variables can be read by just writing x
. How come?
Possible Duplicate:
Why do you need explicitly have the “self” argument into a Python method?
In Python, instance variables must be accessed via self.x
, but global variables can be read by just writing x
. How come?
This is a frequently asked question, but essentially: it is so as to avoid name conflicts or confusion about which of instance or global variables are being accessed.
The philosophy is "Explicit is better than implicit".