isa(x, type) -> Bool

Determine whether x is of the given type.


  1. Check if a value is of a specific type:

    julia> x = 10;
    julia> isa(x, Int)

    This example checks if the value x is of type Int.

  2. Verify type compatibility with abstract types:

    julia> y = [1, 2, 3];
    julia> isa(y, AbstractArray)

    It confirms that y is of type AbstractArray, which includes all array-like types in Julia.

  3. Check for subtype relationship with user-defined types:
    julia> struct Person end;
    julia> struct Student <: Person end;
    julia> s = Student();
    julia> isa(s, Person)

    In this example, isa verifies that s is of type Person, even though it is an instance of the subtype Student.

Common mistake example:

julia> a = 5;
julia> isa(a, Float64)

In this case, the mistake is expecting isa to return true for a being of type Float64. However, since a is an integer (Int), it is not of the requested type. It's essential to understand the type hierarchy and use isa appropriately to avoid such errors.

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

Checking you are not a robot: