How to use the iszero method in Julia

Overview

The iszero(x) method can be used to check if the given value is Not a Numberequal to zero or not.

Syntax

iszero(x) -> Bool
Julia iszero function Syntax

Parameter

This method takes the parameter, x, which represents the value that is to be checked. The argument can be a numeric value or an array.

Return value

This method returns true if the provided value is equal to 0. Otherwise, false is returned.

Code

The code below demonstrates how to use the iszero method.

## find iszero of 0
println( "iszero(0) => $(isone(0))") # returns true
## find iszero of 0.0
println( "iszero(0.0) => $(iszero(0.0))") # returns true
## find iszero of [0, false]]
println( "iszero([0, false]]) => $(iszero([0, false]))") # returns true
## find iszero of [0, true]
println( "iszero([0, true]) => $(iszero([0, true]))") # returns false

Explanation

In the code above, we do the following:

  • Line 2: We use the iszero method with (0) as an argument. The iszero(0) will return true.
  • Line 5: We use the iszero method with (0.0) as an argument. The iszero(0.0) will return true.
  • Line 8: We use the iszero method with an array ([0,false]) as an argument. All the values in the array are evaluated to 0 so true is returned.
  • Line 11: We use the iszero method with an array ([0,true]) as an argument. The true element in the array will be not equal to 0 on converting to a numeric value. So the iszero method returns false as a result.

Free Resources