- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Fluent Python 他们说
You write
len(my_object)
and, ifmy_object
is an instance of a user-defined class, then Python calls the__len__
instance method you implemented ...But for built-in types like
list
,str
,bytearray
, and so on, the interpreter takes a shortcut: the CPython implementation oflen()
actually returns the value of theob_size
field in thePyVarObject
C struct that represent the any variable-sized built-in object in memory.
但是 __len__
仍然至少在其中一些上定义......
>>> 'string'.__len__()
6
>>> [1, 2, 3].__len__()
3
如果 len
不调用这些方法,它们有什么用?如果还有其他类似的例子,他们呢?
最佳答案
CPython 实现默认不调用 __len__()
的事实并不意味着没有任何 Python 库或用户程序会调用。保持方法可用与 API 稳定性有关,即使 CPython 尽可能走捷径也是如此。
关于python - Python 的内置类型是否有多余的特殊方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56613115/
我的服务层有如下方法 public ModuleResponse GetModules(ModuleRequest request) { var response = new ModuleRe
我构建的工具栏与大多数工具栏一样,minHeight 设置为 actionBarSize: 但是,如果我删除这个属性,就完全没有区别了。工具栏保持其 actionBarSize,即使我删除菜单并将
我已经为 SVG 和剪辑路径苦苦挣扎了一段时间。 我正在尝试创建一个三 Angular 形剪辑路径,它将覆盖照片以给顶部一个“三 Angular 形”边缘。 我试图实现与照片完全相同的效果,但三 An
我有一个带有 2 个索引的 PostgreSQL 表。其中一个索引涵盖了 website_id 和 tweet_id 列,是一个唯一的 B 树索引。第二个索引只覆盖 website_id 列,是一个非
我是一名优秀的程序员,十分优秀!