Julia中元素的类型转换——oftype()方法
oftype()
是 julia 中的一个内置函数,用于将给定类型的元素y (比如)转换为x (比如)类型的元素。
Syntax: oftype(x, y)
Parameters:
- x: Specified first type of element.
- y: Specified second type of element.
Returns: It returns the converted type of elements.
示例 1:
# Julia program to illustrate
# the use of oftype() method
# Getting the converted type of elements.
a = 1;
b = 2.0;
println(oftype(a, b))
输出:
2
示例 2:
# Julia program to illustrate
# the use of oftype() method
# Getting the converted type of elements.
a = 1;
b = 2.0;
println(oftype(b, a))
输出:
1.0