Explaining the 'self' variable to a beginner

Viewed 87308

I'm pretty much ignorant of OOP jargon and concepts. I know conceptually what an object is, and that objects have methods. I even understand that in python, classes are objects! That's cool, I just don't know what it means. It isn't clicking with me.

I'm currently trying to understand a few detailed answers that I think will illuminate my understanding of python:

  1. What does the "yield" keyword do in Python?
  2. What is a metaclass in Python?

In the first answer, the author uses the following code as an example:

>>> class Bank(): # let's create a bank, building ATMs
...    crisis = False
...    def create_atm(self) :
...        while not self.crisis :
...            yield "$100"

I don't immediately grok what self is pointing to. This is definitely a symptom of not understanding classes, which I will work on at some point. To clarify, in

>>> def func():
...   for i in range(3):
...     print i

I understand that i points to an item in the list range(3) which, since it is in a function, isn't global. But what does self "point to"?

8 Answers
Related