Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Iterable which is not an iterator

from counter import Counter class GetMyIterable(): def __init__(self): pass def __iter__(self): return Counter() thing = GetMyIterable() from collections.abc import Iterator, Iterable print(issubclass(thing.__class__, Iterator)) print(issubclass(thing.__class__, Iterable)) for i in thing: print(i)

Output:

False True 1 2 3