Are containers always iterable?

感情迁移 提交于 2020-02-13 22:24:50

问题


Is there a scenario where the container is not iterable, according to this graph?


回答1:


Depends on what you mean by always. According to collections.abc

  • a container is an object that implements __contains__ method
  • an iterable is an object that implements __iter__ (or __getitem__, as a fallback)

So, theoretically, no, you can implement a container that is not an iterable. However, all standard python containers (and most containers implemented by libraries) are also iterable.



来源:https://stackoverflow.com/questions/56989687/are-containers-always-iterable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!