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

The type of the iterator

How can we know it is an iterator? We check it.

from collections.abc import Iterator, Iterable
from counter import Counter

cnt = Counter()
print(cnt.__class__.__name__)
print(issubclass(cnt.__class__, Iterator))
print(issubclass(cnt.__class__, Iterable))

Output:

Counter
True
True