跳转到内容

This page is also in English.

Read it in English

Esta página también está en español.

Léela en español

このページは日本語でも読めます。

日本語で読む

对列表的每个元素应用函数(Apply a function to a list,map)

对列表中的每个元素应用一个函数。

怎么写

map(f, list)

f
要应用的函数。接受一个函数。
list
要应用该函数的元素。接受一个列表。

示例

  • map⁡(x↦x2,[1,2,3])=[1,4,9]\displaystyle \operatorname{map}(x \mapsto x^{2}, \left[ 1, 2, 3 \right]) = \left[ 1, 4, 9 \right]
    map(x => x^2, [1, 2, 3])

    在求解器中,map(x => x^2, [1, 2, 3]) 的结果是 [1, 4, 9]。

    在求解器中打开
  • map_thread

    对多个列表中对应的元素应用一个函数。

  • list

    由参数构成的列表。

  • most

    去掉最后一个元素的列表。

  • length

    列表中元素的个数。

  • nest

    对一个值反复应用函数。

  • last

    列表的最后一个元素。