26

In Python it is possible to debug a program by analyzing data types by printing out a variable's type, such as print type(test_var)

Is there something similar in Julia? I am having trouble assigning values to a 2-D array, and knowing the exact types of each variable would help.

2
  • 3
    Are you looking for the function typeof()? :)
    – Kevin
    Commented Apr 24, 2017 at 0:15
  • eltype(test_var) also does the job
    – Vinod
    Commented Oct 31, 2023 at 9:26

1 Answer 1

48

You want typeof and possibly also isa:

julia> a = 2
2

julia> typeof(a)
Int64

julia> typeof("haha")
String

julia> typeof(typeof("haha"))
DataType

julia> typeof(Set([1,3,4]))
Set{Int64}

julia> 1 isa Number
true

julia> 1 isa String
false

julia> "1" isa Number
false

julia> "1" isa String
true

You might also want to use @show as a convenient way to print debug info.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.