Part
or
returns part
i
ofexpr
.
Examples
Extract an element from a list:
Negative indices count from the end:
Part
can be applied on any expression, not necessarily lists.
expr[[0]]
gives the head of expr
:
Parts of nested lists:
You can use Span
to specify a range of parts:
A list of parts extracts elements at certain indices:
Get a certain column of a matrix:
Extract a submatrix of 1st and 3rd row and the two last columns:
Further examples:
Part specification is longer than depth of object.
Assignments to parts are possible:
Of course, part specifications have precedence over most arithmetic operations:
Negative step
Cannot take positions 1
through 3
in {1, 2, 3, 4}
.
Cannot take positions 3
through 1
in {1, 2, 3, 4}
.
Implementation status
- ✅ - full supported