How to compare with the value nothing? I came up with this small piece of lines but it is not working.
A = [1,2,3]
if indexin(USER_INPUT,A) !== nothing
do_someething()
end
Thank you
How to compare with the value nothing? I came up with this small piece of lines but it is not working.
A = [1,2,3]
if indexin(USER_INPUT,A) !== nothing
do_someething()
end
Thank you
julia> isnothing(nothing)
true
indexin
returns an Array
so !== nothing
will always be true
. What do you want to do?
The USE_INPUT is an integer.
indexin(2,A) results in 2
but indexin(4,A) results in nothing.
So, I would like to compare with the result.
As Kristoffer said, those are (zero dimensional) arrays. You could e.g. try
julia> any(isnothing, indexin(1, [1,2,3]))
false
julia> any(isnothing, indexin(9, [1,2,3]))
true
Why not use if USER_INPUT in A
instead?
if any(isnothing, indexin(9, [1,2,3])) === false
println("wahoo")
end
It works well,
Thank you
I am new Julia user. can you provide an example?
if 9 in [1,2,3]
println("wahoo")
end
if 2 in [1,2,3]
println("wohoo")
end
This also works. Thank you