[Tutor] Object Orientation : Class XXX : def __init__

Bill Mill bill.mill at gmail.com
Thu Nov 4 18:57:34 CET 2004


I'm not really sure if I understand you, and I haven't seen any
tutorials like the one you're asking for - the only school for that is

Anyway, about __init__ , you never have to define it as a function. Example:

In [2]: class test:
   ...:     def foo(self): print 'yo'

In [3]: t = test()

In [4]: t.foo()

This works as expected. __init__ is a convenience function which
allows you to initialize the variables in your class. It is
automatically called on object instantiation by the Python

Does that make sense?

Bill Mill
bill.mill at gmail.com

On Thu, 4 Nov 2004 09:40:11 -0800 (PST), kumar s <ps_python at yahoo.com> wrote:
> Dear group,
>  I have a basic question and I am sure it might have
> been churned a lot. However, the concept is initially
> such a rock hard that is not easily palatable.
> Although I have been trying to get a grasp, when it
> comes to coding, I loose the connection why do I have
> to define class: and then always say:
> def __init__ function.
> Could any one help me please defining __init__
> function in terms of a python program.
> Please also point me to some good tutorial (preferably
> example based case where it shows the differences
> between coding some script as an OOP and the other one
> as a simple script with out OOP functionality.
> Thank you,
> Suraj.
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list