Constructor with default parameter : Constructor : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Constructor »

 

Constructor with default parameter


class grocery:
    def __init__(self, name, quantity=1):
        self.name = name
        self.quantity = quantity

items = {}
items['A'= grocery('A')
items['B'= grocery('B',2)

for item in items.keys():
  print "Grocery : ", items[item].name,
  print "tQuantity: ", items[item].quantity



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Constructor