相关疑难解决方法(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万
查看次数

python queue get size,使用qsize()或len()?

我见过的例子,其中qsize()len()已用于计算队列的大小.两者有什么区别?

python size queue

11
推荐指数
1
解决办法
8209
查看次数

标签 统计

python ×2

class ×1

coding-style ×1

optimization ×1

queue ×1

size ×1