- See Also
-
Related Guides
- Expression Structure
- Operations on Vectors
- Math & Counting Operations on Lists
- Regular & Coordinate Arrays
- Elements of Lists
- Handling Arrays of Data
- Memory Measurement & Optimization
- Expressions
- Parts of Expressions
- Language Overview
- GPU Computing
- List Manipulation
- Binary Data
- GPU Computing with NVIDIA
- GPU Computing with Apple
- Tech Notes
-
- See Also
-
Related Guides
- Expression Structure
- Operations on Vectors
- Math & Counting Operations on Lists
- Regular & Coordinate Arrays
- Elements of Lists
- Handling Arrays of Data
- Memory Measurement & Optimization
- Expressions
- Parts of Expressions
- Language Overview
- GPU Computing
- List Manipulation
- Binary Data
- GPU Computing with NVIDIA
- GPU Computing with Apple
- Tech Notes
Length[expr]
gives the number of elements in expr.
Length
Length[expr]
gives the number of elements in expr.
Details
- For special objects like SparseArray, QuantityArray, NumericArray or Association, Length returns the length of the corresponding ordinary list. »
- Otherwise, Length[expr] returns 0 whenever AtomQ[expr] is True.
Examples
open all close allBasic Examples (2)
Length[{a, b, c, d}]Find the length of an Association:
Length[<||>]Length[<|1 -> 2, 3 -> 4|>]Scope (2)
Generalizations & Extensions (5)
Length[x]Length["string"]StringLength gives the number of characters:
StringLength["string"]Explicit numbers have length 0:
Length[123456]Length[1 / 10]Length[3 + I]Length works on SparseArray objects:
SparseArray[{a, b, c, d, e}]Length[%]Length works on structured arrays, like SymmetrizedArray objects:
SymmetrizedArray[{{1, 2} -> a, {2, 3} -> b}, {4, 4}, Antisymmetric[{1, 2}]]Length[%]Applications (5)
Find the number of rows in a matrix:
Length[{{a, b, c}, {d, e, f}}]Find the length of each sublist:
Map[Length, {{a, b}, {a, b, c}, {x}}]Find the number of terms in a polynomial:
Length[1 + x + x ^ 2 + x ^ 9]Find the number of digits in 1000!:
Length[IntegerDigits[1000!]]Get the number of points used to plot a curve:
p = Plot[Sin[x], {x, 0, 20}]Total[Cases[p, x_Line :> Length[x[[1]]], Infinity]]Properties & Relations (2)
Length gives the maximum index that can be used:
Length[{a, b, c, d}]{a, b, c, d}[[4]]For expressions with length greater than 0, Length[expr] equals First[Dimensions[expr]]:
mat = {{1, 2, 3}, {4, 5, 6}}Length[mat] == First[Dimensions[mat]]Possible Issues (5)
Length operates on the FullForm of expressions, not their displayed form:
Sqrt[x]Length[%]FullForm[Sqrt[x]]Rational and complex numbers are atoms, so they have length 0:
Length[1 / 3]FullForm[1 / 3]Length[2 + I]FullForm[2 + I]Numeric expressions are treated like other expressions, not like explicit numbers:
Length[Sqrt[7]]Length[7]Length counts only "arguments", not parts of heads:
Length[h[a, b][x, y, z]]For nonatomic e, Length[e] is equivalent to First[Dimensions[e]]:
exprs = {1, {}, {2}, {{3, 4}, {5, 6}}, SparseArray[{{7}}, {8, 9}]};TableForm[Table[{e//OutputForm, Length[e], Dimensions[e], If[Dimensions[e] === {}, 0, First[Dimensions[e]]]}, {e, exprs}], TableDepth -> 2, TableHeadings -> {{}, {"e", "Length[e]", "Dimensions[e]", "\"First\" dimension"}}]Related Guides
-
▪
- Expression Structure ▪
- Operations on Vectors ▪
- Math & Counting Operations on Lists ▪
- Regular & Coordinate Arrays ▪
- Elements of Lists ▪
- Handling Arrays of Data ▪
- Memory Measurement & Optimization ▪
- Expressions ▪
- Parts of Expressions ▪
- Language Overview ▪
- GPU Computing ▪
- List Manipulation ▪
- Binary Data ▪
- GPU Computing with NVIDIA ▪
- GPU Computing with Apple
Related Links
-

An Elementary Introduction to the Wolfram Language
: Operations on Lists
-

An Elementary Introduction to the Wolfram Language
: Strings and Text
-

An Elementary Introduction to the Wolfram Language
: Ways to Apply Functions
-

An Elementary Introduction to the Wolfram Language
: Expressions and Their Structure
-

NKS|Online
(A New Kind of Science)
History
Introduced in 1988 (1.0) | Updated in 2003 (5.0) ▪ 2014 (10.0)
Text
Wolfram Research (1988), Length, Wolfram Language function, https://reference.wolfram.com/language/ref/Length.html (updated 2014).
CMS
Wolfram Language. 1988. "Length." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/Length.html.
APA
Wolfram Language. (1988). Length. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Length.html
BibTeX
@misc{reference.wolfram_2026_length, author="Wolfram Research", title="{Length}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/Length.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_length, organization={Wolfram Research}, title={Length}, year={2014}, url={https://reference.wolfram.com/language/ref/Length.html}, note=[Accessed: 13-June-2026]}