On this page
  1. range
  2. Import & Availability
  3. Overview & Signature
  4. Common Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

range

Prev: quit | Up: __builtins__ | Next: repr
Rel: bool, int, float, complex, str
Ref: docs.python.org — range
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import range

Overview & Signature

range(stop) -> range object

range(start, stop[, step]) -> range object Return an object that produces a sequence of integers from start (inclusive) to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1.

Common Methods & Attributes

Usage

assert list(range(5)) == [0, 1, 2, 3, 4]
assert list(range(10, 0, -3)) == [10, 7, 4, 1]
assert 500_000 in range(1_000_000)   # O(1) membership test!

Gotchas

REPL Inspect

help(range)

Linked from

Related notes