Skip to content

Count

Count[l, pattern] returns the number of expressions in l matching pattern.

Attributes[Count] := {Protected}

Simple examples

In[1]:= Count[a + b + c^2, _]
Out[1]= 3
In[2]:= Count[a + b + c^2, _, -1]
Out[2]= 5
In[3]:= Count[a + b + c^2, _, Infinity]
Out[3]= 5
In[4]:= Count[a, _, Infinity]
Out[4]= 0
In[5]:= Count[a, _, -1]
Out[5]= 0
In[6]:= Count[a + 2 + c^2, _Integer, Infinity]
Out[6]= 2