Flexible function inputs
Accept lists, tuples, ranges, generators, and other iterable inputs without requiring a concrete container.
Python · Type Alias
collections.abc.Iterable[T] annotates an object that can provide values of type T one at a time. It is the modern replacement for the deprecated typing.Iterable alias.
Iterable[T] describes an object that can provide values of type T one at a time. Use the generic form from collections.abc in modern Python annotations; it can describe inputs such as lists, ranges, generators, and other iterable objects.
collections.abc.Iterable[T]| Name | Type | Description |
|---|---|---|
T | type parameter | The element type yielded by the iterable. |
An iterable object yielding values of the declared type; Iterable[T] is used in annotations rather than producing a runtime value.
Iterable from collections.abc.Iterable[YieldType].Iterable[int].typing.Iterable is deprecated; import Iterable from collections.abc instead.from collections.abc import Iterable
def total(values: Iterable[int]) -> int:
return sum(values)
print(total([1, 2, 3]))
print(total(range(4)))The function accepts any iterable of integers, including a list and a range.
Accept lists, tuples, ranges, generators, and other iterable inputs without requiring a concrete container.
Describe the values yielded by a generator that only produces items.
Build generic aliases whose element type is preserved.
collections.abc.Iterablecollections.abc.Iteratortyping.Iteratoriter()for