📜  在 Julia 中获取元素的数据类型 – typeof() 方法

📅  最后修改于: 2022-05-13 01:55:35.330000             🧑  作者: Mango

在 Julia 中获取元素的数据类型 – typeof() 方法

typeof()是 julia 中的一个内置函数,用于返回指定元素的具体类型。

示例 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}