# take 函数

列表的前几个元素。

## 怎么写

### take(list, n)

**list**

列表。接受一个列表。

**n**

元素个数。接受一个整数。

## 示例

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

  `take([1, 2, 3, 4], 2)`

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

  [在求解器中打开](https://zh.hilberon.com/?q=take%28%5B1%2C%202%2C%203%2C%204%5D%2C%202%29)

## 相关函数

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

  每个元素出现的次数：元素与计数对的列表。
- [table](https://zh.hilberon.com/library/table)

  在一个或多个范围上求值表达式，构建列表。
- [thread](https://zh.hilberon.com/library/thread)

  把函数应用到列表的对应元素上。
- [subsets](https://zh.hilberon.com/library/subsets)

  列表所有保持顺序的子列表，以列表形式给出。
- [total](https://zh.hilberon.com/library/total)

  列表元素之和。
- [sort](https://zh.hilberon.com/library/sort)

  按递增顺序排列的列表。

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