Julia examples - Variable Type
This short tutorials explains about how to get variable type.
How to get Variable datatype in Julia
typeof()
function accepts variable, and returns the variable datatype
Print the result to console using println
statement.
Here is an example
number = 11
println(typeof(number))
number1 = 11.12
println(typeof(number1))
name = "str"
println(typeof(name))
flag = false
println(typeof(flag))
println(typeof(Set([1,2,3])))
Output:
Int64
Float64
String
Bool
Set{Int64}
How to Check given variable is an Integer type
isa
operator checks an given variable or expresion is an given data type. This useful in conditional statement checking such as if else expressions.
variable/expression isa datatype
if an variable is given datatype, returns true,else false.
number = 11
if number isa Number
println("Given value is a Number")
else
println("Not a number")
end