.. include:: The ``range`` Function ====================== .. contents:: :local: .. ot-topic:: python.basics.python_0225_range :dependencies: python.basics.python_0200_sequential_types, python.basics.python_0220_for Iteration over Numbers: ``range()`` ----------------------------------- **Rare:** iteration using indexed access .. code-block:: python :caption: Indexed access in C char hello[] = "Hello World"; for (int i=0; i>> type(range(10**9)) * *Generates* numbers on demand * |longrightarrow| *Generator* ``range()``: Python 2 vs. Python 3 ---------------------------------- **Incompatibility alert:** * Python 2: ``range(10**9)`` *would* explode! * Heritage of the old Pre-Generator days * |longrightarrow| Python 2's ``xrange()`` is a generator .. code-block:: python :caption: If one wants a list in Python 3 (unlikely) ... l = list(range(10**9))