切片
对于字符串,数组,指向数组的指针或切片a,主表达式
a [低:高]
构造一个子字符串或切片。索引表达式low和high选择哪些元素出现在结果中。结果的索引从0开始,长度等于高-低。
对于数组或字符串,索引low和high必须满足0 <= low <= high <= length;对于切片,上限是容量而不是长度。
指标
形式的主要表达
斧头]
表示由x索引的数组,切片,字符串或映射的元素。值x分别称为索引或映射键。适用以下规则:
对于类型A或* A(其中A是数组类型),或者对于类型S(其中S是切片类型):
x must be an integer value and 0 <= x < len(a)a[x] is the array element at index x and the type of a[x] isthe element type of Aif a is nil or if the index x is out of range, a run-time panic occurs制作切片,地图和通道
make(T, n) slice slice of type T with length n and capacity nmake(T, n, m) slice slice of type T with length n and capacity m
y必须是整数值,并且0 <= y <len(pixel [] uint8)。x必须是整数值,并且0 <= x <len(pixel [] []
uint8)。例如,
package mainimport "tour/pic"func Pic(dx, dy int) [][]uint8 { pixels := make([][]uint8, dy) for y := 0; y < dy; y++ { pixels[y] = make([]uint8, dx) for x := 0; x < dx; x++ { pixels[y][x] = uint8(x * y) } } return pixels}func main() { pic.Show(Pic)}


