کلاس دادهها و کارهایی را که روی آن دادهها انجام میشود کنار هم میگذارد. توضیح کامل در درس کلاس و شیء.
class Fruit:
def __init__(self, price_per_kilo, weight):
self.price_per_kilo = price_per_kilo
self.weight = weight
def cost(self):
return self.price_per_kilo * self.weight
banana = Fruit(2000, 5)
print(banana.weight, banana.cost())