# Why \`length(2) == length(\[2\])\`?

**URL:** <https://discourse.julialang.org/t/why-length-2-length-2/117262>\
**Category:** New to Julia\
**Created:** [July 20, 2024, 3:03am UTC](https://discourse.julialang.org/t/why-length-2-length-2/117262 "2024-07-20T03:03:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ykkan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ykkan/32/14541_2.png) [@ykkan](https://discourse.julialang.org/u/ykkan)\
**Post date:** [July 20, 2024, 3:03am UTC](https://discourse.julialang.org/t/why-length-2-length-2/117262/1 "2024-07-20T03:03:09Z")

</div>

Hi everyone,  
What is the idea behind that the `legnth` of a single number is 1 instead of 0? Does anyone know the reason for that design? On the other hand, we have `length([:x])==1`, but when typing `length(:x)`, we will get the error message:  
`ERROR: MethodError: no method matching length(::Symbol)`

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [July 20, 2024, 3:10am UTC](https://discourse.julialang.org/t/why-length-2-length-2/117262/2 "2024-07-20T03:10:35Z")

</div>

Numbers are iterable in julia. See for example:

```julia
julia> for i in 1
           @show i
       end
i = 1

```

Therefore having a single number give the correct length it would have if you were to iterate through it makes sense.  
See [make numbers non-iterable? · Issue #7903 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/7903) for an old and long discussion of this property.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 20, 2024, 6:16am UTC](https://discourse.julialang.org/t/why-length-2-length-2/117262/3 "2024-07-20T06:16:17Z")

</div>

> [@ykkan](#):
>
> 1 instead of 0

You might be thinking of the number of dimensions instead. We can check the dimensions (`size` or `axes`) and count the number (`length` of tuple):

```julia
julia> length(size(1)), length(size([1]))
(0, 1)

```
