Operator Functions

operator.length_hint()

Obtain len(obj) if supported, otherwise a nonnegative estimate from __length_hint__, otherwise default. The estimate need not equal actual iteration length.

Formal Syntax & Structure

python syntaxpython
operator.length_hint(obj, default=0, /)

Parameters & Attributes

NameTypeDescription
objobjectObject to inspect or copy.
defaultintNonnegative integer fallback estimate; used when neither length nor hint is available.

Return Value

int

The int result described above.

Working Example

Example Snippetpython
import operatorit=iter([1,2,3])next(it)print(operator.length_hint(it))
Python Reference