Basic - 2
1. @classmethod, @staticmethod
@classmethod, @staticmethodclass Store:
def __init__(self, name):
self.name = name
self.items = []
def add_item(self, name, price):
self.items.append({
'name': name,
'price': price
})
def stock_price(self):
total = 0
for item in self.items:
total += item['price']
return total
@classmethod
def franchise(cls, store):
new_name = '{} - franchise'.format(store.name)
return cls(new_name)
@staticmethod
def details(store):
return '{}, total stock price: {}'.format(store.name, int(store.stock_price()))
a = Store('Amazon')
a.add_item('macbook', '1100')
Store.franchise(a)
Store.details(a)2. Lambda
3. Python folders
4. Array methods
Last updated