> In a class is every def called a method

Strictly speaking only those that have a 'self' parameter(or
equivalent)
The others are "unbound functions" and pretty useless, usually being
the result of programmer errors!...

> and the def __init__(self) is called the constructor method?

Usually.

> I don't have a problem writting a def I am still not clear on how to
> use a constructor.

Use the constructor to initialise the attributes of your new instance.
When you create an instance by calling a class:

instance = Class(a,b,c)

what happens is that Python creates a blank instance of Class
then calls the __init__ method of the new instance passing in
the arguments you gave to the class, in our case a,b,c.

[ If your class inherits from a superclass then its usually a
good idea to call the superclass init method inside your init
just to make sure the superclass attributes are all set up
properly too. ]

> Is there a site that explains the constructor in
> great detail?

Well I try... But it depends on how great a detail you want. "Great
detail"
implies "not easy to understand", in which case the definitive site is
the
Python documentation!

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to