ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
> ### 遍历 range ~~~ package main import "fmt" func main() { //range 关键字用于for循环中迭代数组(array)、切片(slice)、通道(channel)或集合(map)的元素 number := [5]string{"a", "b", "c", "d", "e"} for k, v := range number { fmt.Println(k, v) } /* 省略key的写法 for _, v := range number { fmt.Println(v) } */ } ~~~ > ### 找出下面错误 ~~~ package main type student struct { Name string Age int } func main() { m := make(map[string]*student) stus := []student{ {Name: "zhouYi", Age: 24}, {Name: "zhouEr", Age: 23}, {Name: "zhouSan", Age: 37}, } for _, stu := range stus { m[stu.Name] = &stu } //for _, v := range m{ // fmt.Println(v) //} } ~~~