• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Buried in cloud files? We can help with Spring cleaning!

    Whether you use Dropbox, Drive, G-Suite, OneDrive, Gmail, Slack, Notion, or all of the above, Dokkio will organize your files for you. Try Dokkio (from the makers of PBworks) for free today.

  • Dokkio (from the makers of PBworks) was #2 on Product Hunt! Check out what people are saying by clicking here.



Page history last edited by PBworks 13 years, 11 months ago

explain __int__


obj3 = MyClass()


(it's the () that creates the object, not the =)


_ _new__ is the constructor: it creates the instance and returns it (overriding: advanced topic)


Along the way, it calls _ _init__ on the *already-created* instance, to

ask it to initialise itself ready for use. So, _ _init__ is an

"initialiser" for the instance, used often. Rarely you override _ _new__, but customizing _ _init__ is common: http://www.python.org/doc/ref/customization.html


obj = mytype.__new__(*args, **kwds)

if isinstance(obj, mytype):

mytype.__init__(obj, *args, **kwds)

return obj


Nevertheless, _ _init__ doesn't construct anything. You can even call

it to reinitialize an existing object.


Also, how can a constructor require 'self' as an argument...?

_ _init__(self, ...)


If the _ _init__ function is called by the constructor it cannot return a

value. However if called as a normal function, it can return a value.

_ _init__ is just a function that gets called during the construction

Comments (0)

You don't have permission to comment on this page.