The combination of parse and length

Hello,
Why is the following combination wrong?

w = "Hello"
print(parse(Int,length(w)))

Thank you.

length(w) is already an integer, you don’t need to parse it.

3 Likes

Hi,
Thanks.
So, when we try to convert one type to the same type, we get an error.

convert is different, convert(::Type{T}, x::T} -> x is generically defined, so you can convert(Int, 2). However, parse is something you specifically do to string-ly values, hence the error you saw.

3 Likes

Hi,
Thank you so much for your reply.
I didn’t mean the convert function.