# Why is length of integers = 1?

**URL:** <https://discourse.julialang.org/t/why-is-length-of-integers-1/22374>\
**Category:** New to Julia\
**Created:** [March 26, 2019, 8:16pm UTC](https://discourse.julialang.org/t/why-is-length-of-integers-1/22374 "2019-03-26T20:16:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [March 26, 2019, 8:16pm UTC](https://discourse.julialang.org/t/why-is-length-of-integers-1/22374/1 "2019-03-26T20:16:05Z")

</div>

Is there any reason to have length of integers equal to 1?

For example, length(100) = 1. Recently, I had a bug in my code because of this. Shouldn’t length(a\_number) result in an error?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [March 26, 2019, 8:29pm UTC](https://discourse.julialang.org/t/why-is-length-of-integers-1/22374/2 "2019-03-26T20:29:57Z")

</div>

Numbers are iterable objects to enable code like the following to _just work_ with integer inputs:

```julia
function triplesum(v)
    s = zero(eltype(v))
    for element in v
        s += 3*element
    end
    return s
end

julia> triplesum(1:5)
45

julia> triplesum(1)
3

```

The length of an iterable is the number of iterations performed to traverse each element (which for a number, as you found, is one).

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 26, 2019, 8:39pm UTC](https://discourse.julialang.org/t/why-is-length-of-integers-1/22374/3 "2019-03-26T20:39:32Z")

</div>

[https://github.com/JuliaLang/julia/issues/7903](https://github.com/JuliaLang/julia/issues/7903)

Enjoy the read 🙂

---

<div class="post-metadata">

**Author:** ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)\
**Post date:** [March 26, 2019, 8:48pm UTC](https://discourse.julialang.org/t/why-is-length-of-integers-1/22374/4 "2019-03-26T20:48:48Z")

</div>

Thank you. Will read the linked issue.
