Finding Variable Types in Julia

In Python, you can debug a program by analyzing data types by printing the type of a variable, for example print type(test_var)

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

+4
source share
1 answer

You want, typeofand 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 can also use it @show as a convenient way to print debugging information.

+12
source

Source: https://habr.com/ru/post/1675473/


All Articles