Home » Julia

Determine the type of a value/variable in Julia

Julia | Example of typeof() function: In this tutorial, we are going to learn how to determine the type of value, variables in the Julia programming language?
Submitted by IncludeHelp, on March 30, 2020

To determine the type of value, variable – we use typeof() function, it accepts a value or a variable or a data type itself and returns the concrete type of the given parameter.

Example 1: Determining the type of values

# Julia | Determining the type of values

println("typeof(0): ", typeof(0))
println("typeof(-0): ", typeof(-0))
println("typeof(0.0): ", typeof(0.0))
println("typeof(-0.0): ", typeof(-0.0))
println("typeof(10): ", typeof(10))
println("typeof(10000): ", typeof(10000))
println("typeof(123.456): ", typeof(123.456))
println("typeof('X'): ", typeof('X'))
println("typeof(\"Hello\"): ", typeof("Hello"))

Output

typeof(0): Int64
typeof(-0): Int64
typeof(0.0): Float64
typeof(-0.0): Float64
typeof(10): Int64
typeof(10000): Int64
typeof(123.456): Float64
typeof('X'): Char
typeof("Hello"): String

Example 2: Determining the type of variables

# Julia | Determining the type of variables

a = 0
b = -0
c = 0.0
d = -0.0
e = 10
f = 10000
g = 123.456
h = 'X'
i = "Hello"

println("typeof(a): ", typeof(a))
println("typeof(b): ", typeof(b))
println("typeof(c): ", typeof(c))
println("typeof(d): ", typeof(d))
println("typeof(e): ", typeof(e))
println("typeof(f): ", typeof(f))
println("typeof(g): ", typeof(g))
println("typeof(h): ", typeof(h))
println("typeof(i): ", typeof(i))

Output

typeof(a): Int64
typeof(b): Int64
typeof(c): Float64
typeof(d): Float64
typeof(e): Int64
typeof(f): Int64
typeof(g): Float64
typeof(h): Char
typeof(i): String

Example 3: Determining the type of datatypes

# Julia | Determining the type of datatypes

println("typeof(Bool): ", typeof(Bool))
println("typeof(Char): ", typeof(Char))
println("typeof(Int32): ", typeof(Int32))
println("typeof(Float64): ", typeof(Float64))
println("typeof(String): ", typeof(String))

Output

typeof(Bool): DataType
typeof(Char): DataType
typeof(Int32): DataType
typeof(Float64): DataType
typeof(String): DataType


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.