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

Numbers are iterable in julia. See for example:

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 for an old and long discussion of this property.

4 Likes