[Tutor] class arguments?

Alan Gauld alan.gauld at btinternet.com
Thu Jan 22 23:01:39 CET 2009


"spir" <denis.spir at free.fr> wrote 
> is there a way to give arguments to a class definition? Eg
> 
> class MonoList(list, typ, number):
> item_type = typ
> item_number = number

Yes thats what the __init__ method is for.

class MonoList:
   def __init__(self, lst, typ, num):
       self.item_type = typ
       self.number = num
      etc...

myList = MonoList([1,2,3], int, 3)    # or whatever...

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list