我创建了类命名产品,如何创建产品类型的对象变量? 我为商店创建的这个课程用于跟踪产品数据。
class Product:
"""Class for representing product"""
def __init__(self, ProdName, ProdNumber, ProdPrice, InvCount):
self.Name = ProdName
self.Number = ProdNumber
self.Price = ProdPrice
self.Inven = InvCount
self.__PropTax = 0.20
答案 0 :(得分:1)
这在python中非常简单。
In [1]: class Product:
...: """Class for representing product"""
...: def __init__(self, ProdName, ProdNumber, ProdPrice, InvCount):
...: self.Name = ProdName
...: self.Number = ProdNumber
...: self.Price = ProdPrice
...: self.Inven = InvCount
...: self.__PropTax = 0.20
...:
In [2]: P = Product("name", "PROD123", 1.0, 10)
In [3]: P.Name
Out[3]: 'name'
In [4]: P.Number
Out[4]: 'PROD123'
In [5]: P.Price
Out[5]: 1.0
In [6]: P.Inven
Out[6]: 10
如果您对此有何疑问,请与我联系。
另外,我建议你回答这个问题:https://stackoverflow.com/questions/3332454/
答案 1 :(得分:0)
object_of_type_product =产品(ProdName1,ProdNumber1,ProdPrice1,InvCount1)