The iszero(x)
method can be used to check if the given value is
iszero(x) -> Bool
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.
This method returns true
if the provided value is equal to 0
. Otherwise, false
is returned.
The code below demonstrates how to use the iszero
method.
## find iszero of 0println( "iszero(0) => $(isone(0))") # returns true## find iszero of 0.0println( "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
In the code above, we do the following:
iszero
method with (0)
as an argument. The iszero(0)
will return true
.iszero
method with (0.0)
as an argument. The iszero(0.0)
will return true
.iszero
method with an array ([0,false]
) as an argument. All the values in the array are evaluated to 0
so true
is returned.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.