is it possible to put a array within a slice? I tried [][2]int
, but I can't figure out how to create an instance. The end result should be a mutable slice around an immutable 2 item array.
In python it would look like: [(1,2),(3,4)]
.
is it possible to put a array within a slice? I tried [][2]int
, but I can't figure out how to create an instance. The end result should be a mutable slice around an immutable 2 item array.
In python it would look like: [(1,2),(3,4)]
.
Go syntax uses {}
braces for slices and arrays.
s := [][2]int{
[2]int{1, 2},
[2]int{3, 4},
}
But you can elide the inner types in the literal when they can be inferred:
s := [][2]int{{1, 2}, {3, 4}}
s = append(s, [2]int{5, 6})