func main(){ //定义map第一种方式 var map1 map[string]string //声明map map1 = make(map[string]string, 20) //初始化map map1["num1"] = "xiaoming" map1["num2"] = "tom" fmt.Println(map1) //定义map第二种方式 map2 := make(map[string]string, 10) map2["num1"] = "xiaok" map2["num2"] = "xiaohei" fmt.Println(map2) //定义map第三种方式 map3 := map[string]int{ "key1" : 56, "key2" : 66, //map最后一个key和v也不能少逗号 } fmt.Println(map3) //map套用 stu_map := make(map[string]map[string]string) stu_map["mum_xues1"] = make(map[string]string, 3) stu_map["mum_xues1"]["name"] = "tom" stu_map["mum_xues1"]["sex"] = "男" stu_map["mum_xues1"]["addr"] = "杭州" stu_map["mum_xues2"] = make(map[string]string, 3) stu_map["mum_xues2"]["name"] = "aslis" stu_map["mum_xues2"]["sex"] = "男" stu_map["mum_xues2"]["addr"] = "北京" fmt.Println(stu_map) fmt.Println(stu_map["mum_xues2"]) fmt.Println(stu_map["mum_xues2"]["name"]) }