朱莉娅 |带有示例的 checkindex()函数
checkindex()
是 julia 中的内置函数,如果给定的索引值在范围内,则用于返回 true,否则返回 false。
Syntax: checkindex(Bool, Range, Index)
Parameters: This function accepts three parameters which are illustrated below:-
- Bool: This says that this function will return boolean values as output.
- Range: It is the specified range.
- Index: It is the index value which are going to be calculated either it lies in the range or not.
Returns: It returns the value true if the index value lies in the range else false.
以下是一些说明上述函数的代码:
示例 #1:
# Julia Program for illustration of
# checkindex() function
# Initializing a range value from 1 to 10
Range = 1:10
# Initializing a index value of 5
Index = 5
# Calling the checkindex() function
A = checkindex(Bool, Range, Index)
# Getting the value true or false
println(A)
输出:
true
示例 #2:
# Julia Program for illustration of
# checkindex() function
# Initializing a range value from 1 to 10
Range = 1:10
# Initializing a index value of 15
Index = 15
# Calling the checkindex() function
A = checkindex(Bool, Range, Index)
# Getting the value true or false
println(A)
输出:
false