Are you supposed to use self
when referencing a member function in Python (within the same module)?
More generally, I was wondering when it is required to use self
, not just for methods but for variables as well.
Adding an answer because Oskarbi's isn't explicit.
You use self
when:
You don't use self
when
instance = MyClass()
, you call MyClass.my_method
as instance.my_method(some_var)
not as instance.my_method(self, some_var)
.These don'ts are just examples of when not to use self. The dos are when you should use it.