/* 打印 map */ for country := range countryCapitalMap { fmt.Println("Capital of",country,"is",countryCapitalMap[country]) }
/* 删除元素 */ delete(countryCapitalMap,"France"); fmt.Println("Entry for France is deleted")
fmt.Println("删除元素后 map")
/* 打印 map */ for country := range countryCapitalMap { fmt.Println("Capital of",country,"is",countryCapitalMap[country]) } }
编译运行以上范例,输出结果如下:
1 2 3 4 5 6 7 8 9 10 11
$ go run main.go 原始 map Capital of France is Paris Capital of Italy is Rome Capital of Japan is Tokyo Capital of India is New Delhi Entry for France is deleted 删除元素后 map Capital of Italy is Rome Capital of Japan is Tokyo Capital of India is New Delhi