range

An immutable sequence of integers created with range(). You can reuse it without creating a full list; use list() when you need a list.

Syntax

range(stop, /) | range(start, stop, step=1, /)

Constructor parameters

NameDescription
startInt
Start value (inclusive)
Depends on overload · Positional only
Default: 0
stopInt
End value (exclusive)
Required · Positional only
No default
stepInt
Difference between consecutive values. Use a negative value to count down; 0 raises an error.
Depends on overload · Positional only
Default: 1

Returns

Example

numbers = range(0, 10, 2)
text(str(list(numbers)))
text(str(numbers.index(4)))

Fields

NameDescription
startInt
Inclusive starting boundary.
stopInt
End boundary, excluded from the sequence.
stepInt
Difference between consecutive values.
Field example
numbers = range(2, 10, 2)
text(str(numbers.start))

Methods

2 methods

range.count

Return how many times value appears: 0 or 1.

Syntax

range.count(value, /)

Parameters

NameDescription
valueAny?
Value to look for. Numeric values are compared by value, so 1.0 equals 1.
Required · Positional only
No default

Returns

Int

Example

range(0, 10, 2).count(4)

range.index

Return the first index of value. Raises ValueError if it is absent.

Syntax

range.index(value, /)

Parameters

NameDescription
valueAny?
Value to look for. Numeric values are compared by value, so 1.0 equals 1.
Required · Positional only
No default

Returns

Int

Example

range(0, 10, 2).index(4)