只是好奇,
有没有使用任何区别(优缺点) len()
或def __len__()
当我建立一个类? 而这是最好的Python的风格?
class foo(object):
def __init__(self,obs=[])
self.data = obs
self.max = max(obs)
self.min = min(obs)
self.len = len(obs)
要么
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)