Skip to content

Take

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

Take[list, n]
    gives the first n elements of list.
Take[list, -n]
    gives the last n elements.
Take[list, {m, n}]
    gives elements m through n.
Take[list, {m, n, s}]
    gives elements m through n in steps of s.
Take[list, {m}]
    gives the single element at position m (wrapped in the head of list).
Take[list, spec1, spec2, ...]
    takes elements at successive levels, e.g. a sub-block of a matrix.

Negative indices count from the end; UpTo[n], All, and None are also accepted
as specifications. Indices are 1-based; out-of-range requests leave the
expression unevaluated. Take operates on any expression, not just List.

Examples

No verified examples yet for this function.

Implementation notes

Attributes: NHoldRest, Protected.

Implementation status

Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

References

Notes & additional examples

Worked examples

In[1]:= Take[{a, b, c, d, e}, 3]
Out[1]= {a, b, c}
In[1]:= Take[{a, b, c, d, e}, -2]
Out[1]= {d, e}
In[1]:= Take[Range[10], {2, 8, 2}]
Out[1]= {2, 4, 6, 8}
In[1]:= Take[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 2, 2]
Out[1]= {{1, 2}, {4, 5}}
In[1]:= Take[Table[Fibonacci[n], {n, 1, 15}], {3, 15, 3}]
Out[1]= {2, 8, 34, 144, 610}

Notes

Take[list, n] takes the first n elements, Take[list, -n] the last n, and Take[list, {m, n}] (optionally {m, n, s} with a step) an inclusive index range. Indices are 1-based and negative indices count from the end; UpTo[n], All, and None are also accepted. Multiple specifications act level by level, so Take[mat, 2, 2] extracts the top-left 2x2 sub-block of a matrix. Take operates on any expression, not only List; out-of-range requests are left unevaluated.