问题
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