# 整数范围（Range of whole numbers，range）

某个范围内的整数，以列表形式给出。

## 怎么写

### range(n)

从 1 到 n。

**n**

最后一个数；列表从 1 开始。接受一个整数。

### range(a, b)

从 a 到 b。

**a**

第一个数。接受一个数。

**b**

最后一个数。接受一个数。

### range(a, b, step)

从 a 到 b，按步长。

**a**

第一个数。接受一个数。

**b**

最后一个数。接受一个数。

**step**

相邻数之间的步长。接受一个数。

## 示例

- $\displaystyle \operatorname{range}(5) = \left[ 1, 2, 3, 4, 5 \right]$

  `range(5)`

  在求解器中，`range(5)` 的结果是 `[1, 2, 3, 4, 5]`。

  [在求解器中打开](https://zh.hilberon.com/?q=range%285%29)
- $\displaystyle \operatorname{range}(2, 6) = \left[ 2, 3, 4, 5, 6 \right]$

  `range(2, 6)`

  在求解器中，`range(2, 6)` 的结果是 `[2, 3, 4, 5, 6]`。

  [在求解器中打开](https://zh.hilberon.com/?q=range%282%2C%206%29)
- $\displaystyle \operatorname{range}(1, 10, 3) = \left[ 1, 4, 7, 10 \right]$

  `range(1, 10, 3)`

  在求解器中，`range(1, 10, 3)` 的结果是 `[1, 4, 7, 10]`。

  [在求解器中打开](https://zh.hilberon.com/?q=range%281%2C%2010%2C%203%29)

## 相关函数

- [replace_part](https://zh.hilberon.com/library/replace_part)

  把某个位置上的部分替换后的列表；写作 position -> value。
- [prepend](https://zh.hilberon.com/library/prepend)

  在开头添加一个元素后的列表。
- [rest](https://zh.hilberon.com/library/rest)

  去掉第一个元素后的列表。
- [position](https://zh.hilberon.com/library/position)

  某个值在列表中出现的位置，以位置列表表示。
- [reverse](https://zh.hilberon.com/library/reverse)

  逆序排列的列表。
- [partition](https://zh.hilberon.com/library/partition)

  将列表按给定长度拆分为若干块。

---
Source: https://zh.hilberon.com/library/range
