gives the first element in expr.
gives the first element if it exists, or def otherwise.
- First[expr] is equivalent to expr[].
- First has attribute HoldRest. In First[expr,def], def is evaluated only if it is to be returned.
Examplesopen allclose all
Basic Examples (5)
Extract the first element of a list:
Extract the first row of a matrix:
Extract the first element of an association:
The head need not be List:
Return x if there are zero elements:
Generalizations & Extensions (2)
Properties & Relations (1)
First[expr] is equivalent to expr[]:
Possible Issues (2)
The expression is evaluated before First is applied:
First always operates on the FullForm of expressions:
Introduced in 1988
Updated in 2014