push!()とappend!()の違い
Julia.iconのpush!()とappend!()の違い
どちらもベクトルに要素を追加するのに使えるが、ちょっと違いがある
push!()はそのまま入れる
code:jl
vec = Int64[]
push!(vec, 1)
push!(vec, 1, 2) # ERROR: MethodError: Cannot convert an object of type Vector{Int64} to an object of type Int64 vec = Vector{Int64}[]
push!(vec, 1) #ERROR: MethodError: Cannot convert an object of type Int64 to an object of type Vector{Int64} append!()は要素に分解して入れる
1枚皮を剥くあんも.icon
code:jl
vec = Int64[]
append!(vec, 1)
append!(vec, 1], [2) # ERROR: MethodError: Cannot convert an object of type Vector{Int64} to an object of type Int64
vec = Vector{Int64}[]
append!(vec, 1) # ERROR: MethodError: Cannot convert an object of type Int64 to an object of type Vector{Int64}
append!(vec, 1, 2) # ERROR: MethodError: Cannot convert an object of type Int64 to an object of type Vector{Int64} append!(vec, 1], [2)