-1
class Team :
    def __init__(self):
        print "object instantiated"

To create an object of Team class,

>>> obj = Team()
object instantiated

From obj I can access member of Team class. But why is the following allowed?

>>> y = obj.__init__()
object instantiated

here some question it raises.

  1. Why obj is able to call __init__() , is __init__() just like another method?

  2. Whenever __init__() is called it will create an object (correct if i'm wrong here), so should y hold another instance of Team?

Chris Morgan
  • 79,487
  • 22
  • 198
  • 207
navyad
  • 3,533
  • 6
  • 43
  • 78

1 Answers1

2

All the "magic" (double underscore) methods are available as regular methods, in addition to their special uses. The __init__ method does not actually create the object instance, it merely initializes the object after the __new__ method has created it. (Note that __init__ does not return anything, so y will be None after y = obj.__init__().)

Abe Karplus
  • 7,960
  • 2
  • 24
  • 24