typeof

typeof(x)

Get the concrete type of x.

Examples

  1. Get the type of a variable:

    julia> x = 5;
    julia> typeof(x)
    Int64

    This example returns the concrete type Int64 of the variable x.

  2. Check the type of a string:

    julia> str = "Hello, Julia!";
    julia> typeof(str)
    String

    It returns the concrete type String of the string variable str.

  3. 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 array arr.

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.

*Required Field
Details

Checking you are not a robot: