Length
Length
Length[ list ] returns the number of elements in a list.
Usages
Length[ list ]
Length[ list ] returns the number of elements in list. list can also be a set.
| Example | in | out |
|---|---|---|
| A list with three elements. | Length[ {2,5,7} ] |
3 |
| Only the elements of the outer list are counted. A list inside the list counts as one element. | Length[ { {1,2,3,4}, 5, {6,7} } ] |
3 |
| The empty list. | Length[ {} ] |
0 |
| A set. | Length[ Set[1,2,3] ] |
3 |
Details
| Invalid input | Result |
|---|---|
Length[ 5 ] |
Left unevaluated: the result is Length[ 5 ] itself. The argument must be a list or a set. |
Length[ x+y+z ] |
Left unevaluated. Length does not count the terms of a sum. |
Length[ {1,2}, {3} ] |
Left unevaluated: Length takes exactly one argument. |
See also: Concat, ConstantArray, Tally