Skip to content

Part

Returns the nth element of a list.

$ wo 'Part[{7, 6, 4}, 2]'
6

Part extraction using [[]] notation

The [[n]] notation is equivalent to Part[..., n].

$ wo '{1, 2, 3}[[2]]'
2
$ wo '{a, b, c, d}[[3]]'
c

Part extraction from variables

$ wo 'x = {10, 20, 30}; x[[2]]'
20
$ wo 'list = {a, b, c}; list[[1]]'
a

Out of bounds error

Attempting to access an index beyond the list length returns an error.

$ wo '{1, 2, 3}[[5]]'

Part::partw: Part 5 of {1, 2, 3} does not exist.
{1, 2, 3}[[5]]
$ wo 'x = {1, 2}; x[[10]]'

Part::partw: Part 10 of {1, 2} does not exist.
{1, 2}[[10]]