GO语言学习笔记——map_1
暑假在学go,做个记录笔记,直接上代码
func main() {
good:=make(map[string]int,3)//make方法初始化一个map,第二个参数为capacity而不是len
score:=map[string]int{"张三":100,"李四":56,"王五":78}
pass:=make(map[string]int,3)
println("good的长度为:",len(good))
for name,score:=range score{
fmt.Println(name,":",score)
if score>60{
pass[name]=score
}
if score>85{
good[name]=score
}
}//成绩大于60及格,成绩大于85优秀
if v,ok:=score["贾六"];ok{
fmt.Println("贾六的成绩为",v)
}else {
fmt.Println("贾六的成绩没有登记")
}//go中判断map里的key是否存在的方法
fmt.Println("通过:",pass)
fmt.Println("优秀:",good)
delete(score,"张三")
delete(pass,"张三")
delete(good,"张三")
//delete删除指定map里的指定key
fmt.Println(score,pass,good)
}