typeof()
是 julia 中的一个内置函数,用于返回指定元素的具体类型。
Syntax: typeof(x)
Parameters:
- x: Specified element.
Returns: It returns the concrete type of the specified elements.
示例 1:
# Julia program to illustrate
# the use of typeof() method
# Getting the concrete type of
# the specified elements.
a = 1//2;
b = 1 / 2;
c = 7 % 2;
d = 2;
println(typeof(a))
println(typeof(b))
println(typeof(c))
println(typeof(d))
输出:
Rational{Int64}
Float64
Int64
Int64
示例 2:
# Julia program to illustrate
# the use of typeof() method
# Getting the concrete type of
# the specified elements.
a = [1, 2, 3, 4];
b = [1 2; 3 4];
c = [1 2; 3.5 4];
d = [1 2; 3 4;5 4];
println(typeof(a))
println(typeof(b))
println(typeof(c))
println(typeof(d))
输出:
Array{Int64, 1}
Array{Int64, 2}
Array{Float64, 2}
Array{Int64, 2}