mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Add different array declaration syntax
This commit is contained in:
parent
2d746ee781
commit
4a3538d60c
@ -151,12 +151,16 @@ a = Int64[] # => 0-element Int64 Array
|
||||
|
||||
# 1-dimensional array literals can be written with comma-separated values.
|
||||
b = [4, 5, 6] # => 3-element Int64 Array: [4, 5, 6]
|
||||
b = [4; 5; 6] # => 3-element Int64 Array: [4, 5, 6]
|
||||
b[1] # => 4
|
||||
b[end] # => 6
|
||||
|
||||
# 2-dimentional arrays use space-separated values and semicolon-separated rows.
|
||||
matrix = [1 2; 3 4] # => 2x2 Int64 Array: [1 2; 3 4]
|
||||
|
||||
# Arrays of a particular Type
|
||||
b = Int8[4, 5, 6] # => 3-element Int8 Array: [4, 5, 6]
|
||||
|
||||
# Add stuff to the end of a list with push! and append!
|
||||
push!(a,1) # => [1]
|
||||
push!(a,2) # => [1,2]
|
||||
|
Loading…
Reference in New Issue
Block a user