Typing and Generics

typing.Collection

An interface combining iteration, membership testing and length. It does not promise indexing or mutability. Deprecated typing alias; prefer collections.abc.Collection in modern code (3.9+).

Formal Syntax & Structure

python syntaxpython
typing.Collection[T]

Return Value

type expression

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import Collection
def summary(items:Collection[int])->tuple[int,bool]: return len(items), 2 in itemsprint(summary({1,2,3}))
Python Reference