ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
创建: `arr1 := new([len]type)` `slice1 := make([]type, len)` 初始化: `arr1 := [...]type{i1, i2, i3, i4, i5}` `arrKeyValue := [len]type{i1: val1, i2: val2}` `var slice1 []type = arr1[start:end]` (1)如何截断数组或者切片的最后一个元素: `line = line[:len(line)-1]` (2)如何使用`for`或者`for-range`遍历一个数组(或者切片): ~~~ for i:=0; i < len(arr); i++ { … = arr[i] } for ix, value := range arr { … } ~~~ (3)如何在一个二维数组或者切片`arr2Dim`中查找一个指定值`V`: ~~~ found := false Found: for row := range arr2Dim { for column := range arr2Dim[row] { if arr2Dim[row][column] == V{ found = true break Found } } } ~~~