Nov-16-2017, 03:22 PM
Hi All,
I am new to programming & trying to learn python.
I have created Product class(as Parent) & Inventory (as child) class. How can i use attributes declared in product class in inventory class. In the below example i want to use Product attribute 'pcost' in inventory class.
In Cost function i want to do pcost * pnbr.
I am new to programming & trying to learn python.
I have created Product class(as Parent) & Inventory (as child) class. How can i use attributes declared in product class in inventory class. In the below example i want to use Product attribute 'pcost' in inventory class.
In Cost function i want to do pcost * pnbr.
class Product(): def __init__(self,pname,pid,pcost): self.pname = pname self.pid=pid self.pcost=pcost class Inventory(Product): def __init__(self,pnbr,products): Product.__init__(self,pname,pid,pcost) self.pnbr=pnbr def cost(self): self.cost=self.pcost*self.pnbr