Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding out types of variables in Julia

Tags:

types

julia

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.

like image 494
Ricardo Iglesias Avatar asked Apr 24 '17 00:04

Ricardo Iglesias


1 Answers

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.

like image 128
Lyndon White Avatar answered Sep 24 '22 20:09

Lyndon White