class Goods:
id_count = 0
#類方法:下面這種寫法是裝飾器寫法,classmethod用來定義類方法
@classmethod
def generate_id(cls):
cls.id_count += 1
return cls.id_count
def __init__(self):
self.id = str(self.generate_id()).zfill(5)
self.name = ''
self.price = 0
self.discount = 1
g1 = Goods()
print(g1.id)