algorithm - Doubts in Python code -


i'm reading book of algorithms in python, , i'm new python.

i can't understand example:

class bunch(dict):     def __init__(self, *args, **kwds):         super(bunch, self).__init__(*args, **kwds)         self.__dict__ = self  x = bunch(name="jayne cobb", position="public relations") print x.name 

some questions:

  • what meaning of * , ** in parameters "args" , "kwds"?
  • what meaning of "super"?
  • in classe extending "dict" class? built-in class?

best regards,

*args means: collect parameters without name in list:

def x(a, *args): pass x(1, 2, 3) 

assigns a=1 , args=[2,3].

**kwargs assigns parameters name dict kawrgs:

def x(a, **kw): pass x(1, b=2, c=3) 

assigns a=1 , kw={b=2, c=3}.

the code super(bunch, self).__init__(*args, **kwds) reads: call method __init__ of bunch instance self , parameters *args, **kwds. it's standard pattern initialize superclasses (docs super)

and yes, dict built-in data type dictionaries.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -