Skip to content

Length

Length[expr] returns the length of expr.

Attributes[Length] := {Protected}

Simple examples

In[1]:= Length[{1, 2, 3, 4}]
Out[1]= 4
In[2]:= Length[{}]
Out[2]= 0
In[3]:= Length[{5}]
Out[3]= 1

Further examples

expr need not have a List head:

In[1]:= Length[foo[1, 2]]
Out[1]= 2
The length of an atomic expression is zero:
In[2]:= Length[a]
Out[2]= 0
In[3]:= Length[2.5]
Out[3]= 0
In[4]:= Length["hello"]
Out[4]= 0