gives the last element in expr.


gives the last element if there are any elements, or def otherwise.


  • Last[expr] is equivalent to expr[[-1]].
  • Last has attribute HoldRest. In Last[expr,def], def is evaluated only if it is to be returned.


open allclose all

Basic Examples  (5)

Extract the last element of a list:

Extract the last row of a matrix:

Extract the last element of an association:

The head need not be List:

Return x if there are zero elements:

Generalizations & Extensions  (1)

Last works on SparseArray objects:

Properties & Relations  (1)

Last[expr] is equivalent to expr[[-1]]:

Possible Issues  (2)

The expression is evaluated before Last is applied:

Last always operates on the FullForm of expressions:

Introduced in 1988
Updated in 2014