Używanie len () i def __len __ (self): aby zbudować klasę
Po prostu ciekawy
Czy jest jakaś różnica (zalety i wady) pomiędzy używaniemlen()
lubdef __len__()
kiedy buduję klasę? A jaki jest najlepszy styl Pythona?
class foo(object):
def __init__(self,obs=[])
self.data = obs
self.max = max(obs)
self.min = min(obs)
self.len = len(obs)
lub
class foo(object):
def __init__(self,obs=[])
self.data = obs
self.max = max(obs)
self.min = min(obs)
def __len__(self):
return len(self.data)