相关疑难解决方法(0)

使用len()和def __len __(self):构建一个类

只是好奇,

使用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)
Run Code Online (Sandbox Code Playgroud)

要么

   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)
Run Code Online (Sandbox Code Playgroud)

python optimization coding-style class

29
推荐指数
2
解决办法
3万
查看次数

标签 统计

class ×1

coding-style ×1

optimization ×1

python ×1