Skip to content

Tag: self

self in Python references to variable rather than the class [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed last month. Improve this question So,

Python classes self.variables

I have started learning python classes some time ago, and there is something that I do not understand when it comes to usage of self.variables inside of a class. I googled, but couldn’t find the answer. I am not a programmer, just a python hobbyist. Here is an example of a simple class, with two ways of defining it: 1)first

When do you use ‘self’ in Python?

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. Answer Adding an answer because Oskarbi’s isn’t explicit. You use self when: Defining an instance method. It is passed automatically as the