First

First[expr]
gives the first element in expr.

First[expr,def]
gives the first element if it exists, or def otherwise.

DetailsDetails

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

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Extract the first element of a list:

In[1]:=
Click for copyable input
Out[1]=

Extract the first row of a matrix:

In[1]:=
Click for copyable input
Out[1]=

Extract the first element of an association:

In[1]:=
Click for copyable input
Out[1]=

The head need not be List:

In[1]:=
Click for copyable input
Out[1]=

Return if there are zero elements:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Introduced in 1988
(1.0)
Translate this page: