Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Type Alias

Iterable

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.

Since
3.9

How it works

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.

Syntax

collections.abc.Iterable[T]

Parameters

NameTypeDescription
Ttype parameterThe element type yielded by the iterable.

Returns

An iterable object yielding values of the declared type; Iterable[T] is used in annotations rather than producing a runtime value.

Key points

  • Modern annotations should import Iterable from collections.abc.
  • A generator that only yields values can be annotated with Iterable[YieldType].
  • The type is parameterized with square brackets, such as Iterable[int].

Common mistakes

  • typing.Iterable is deprecated; import Iterable from collections.abc instead.

Example: Annotate a function accepting iterable integers

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.

When to use it

Flexible function inputs

Accept lists, tuples, ranges, generators, and other iterable inputs without requiring a concrete container.

Generator return annotations

Describe the values yielded by a generator that only produces items.

Reusable type aliases

Build generic aliases whose element type is preserved.

  • collections.abc.Iterable
  • collections.abc.Iterator
  • typing.Iterator
  • iter()
  • for

Source: typing — Support for type hints. Checked 2026-10-15.