typeof
typeof(x)
Get the concrete type of x
.
Examples
-
Get the type of a variable:
julia> x = 5; julia> typeof(x) Int64
This example returns the concrete type
Int64
of the variablex
. -
Check the type of a string:
julia> str = "Hello, Julia!"; julia> typeof(str) String
It returns the concrete type
String
of the string variablestr
. - Determine the type of an array:
julia> arr = [1, 2, 3, 4, 5]; julia> typeof(arr) Array{Int64,1}
It returns the concrete type
Array{Int64,1}
of the arrayarr
.
Common mistake example:
julia> typeof(10, 20, 30)
ERROR: MethodError: no method matching typeof(::Int64, ::Int64, ::Int64)
In this example, the typeof
function is mistakenly used with multiple arguments. The typeof
function expects only one argument, so ensure that you pass a single value or variable to it.
See Also
BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.