0

consider this simple class:

class A:
    def __init__(self):
        pass

    def afunc(self):
        pass

Typically self is a reference to the object, but the init function is responsible for creating the object so how can self be a reference to something that doesn't exist? What is the difference in self for these two functions?

wjandrea
  • 23,210
  • 7
  • 49
  • 68
  • 1
    *"is responsible for creating the object"* - no, it isn't. It's responsible for *initialising it* once created. `__new__`, which is a classmethod, creates the object. – jonrsharpe Aug 19 '20 at 22:26

1 Answers1

0

When __init__ is called self does exist.
__init__ is for initializing, and __new__ creates it.

cajomar
  • 408
  • 4
  • 9