5.3. Abstract Builtin ABC
from collections.abc import *
Container
Hashable
Iterable
Iterator
Reversible
Generator
Callable
Collection
Sequence
MutableSequence
ByteString
Set
MutableSet
Mapping
MutableMapping
MappingView
ItemsView
KeysView
ValuesView
Awaitable
Coroutine
AsyncIterator
AsyncGenerator
Protocol |
Methods |
---|---|
Callable |
|
Container |
|
Hashable |
|
Reversible |
|
Iterable |
|
Iterator |
|
Generator |
|
Collection |
|
Sequence |
|
MutableSequence |
|
ByteString |
|
Set |
|
MutableSet |
|
Mapping |
|
MutableMapping |
|
MappingView |
|
ItemsView |
|
KeysView |
|
ValuesView |
|
Awaitable |
|
Coroutine |
|
AsyncIterator |
|
AsyncGenerator |
|
5.3.1. Use Case - 1
>>> data = range(0,3)
>>>
>>>
>>> hasattr(data, '__iter__')
True
>>>
>>> hasattr(data, '__next__')
False
>>> result = iter(data)
>>>
>>>
>>> hasattr(result, '__iter__')
True
>>>
>>> hasattr(result, '__next__')
True
5.3.2. Use Case - 2
>>> result = enumerate(['a', 'b', 'c'])
>>>
>>>
>>> hasattr(result, '__iter__')
True
>>>
>>> hasattr(result, '__next__')
True