Julia 中級
Anthony Markham
Quantitative Developer
struct 定義結構。struct 宣告中縮排。struct Person
age
height
location
end
steve = Person(18, 180, "London")
println(steve.height)
180
steve 的型別是 Person。struct Person
age
height
location
end
steve = Person(18, 180, "London")
println(typeof(steve))
Person
# It's Steve's birthday!
steve = Person(18, 180, "London")
steve.age = 19
setfield!: immutable struct of type Person cannot be changed
mutable 建立可變結構。mutable struct Person
age
height
location
end
steve = Person(18, 180, "London")
steve.age = 19
println(steve)
Person(19, 180, "London")
mutable struct Person
age::Int64
height::Int64
location::String
end
steve = Person(18.5, 180, "London")
InexactError: Int64(18.5)
Julia 中級