delete
1. delete
- 使用 delete() 内建函数从 map 中删除一组键值对,delete() 函数的格式如下:
delete(map, 键)
其中 map 为要删除的 map 实例,键为要删除的 map 中键值对的键。
package main
import "fmt"
func main() {
mapNum := make(map[string]int)
mapNum["key1"] = 1
mapNum["key2"] = 2
mapNum["key3"] = 3
mapNum["key4"] = 4
delete(mapNum, "key1")
//delete key1后输出map集合key和value
for k, v := range mapNum {
fmt.Printf("key:%s value:%d \n", k, v)
}
}
//结果
key:key2 value:2
key:key3 value:3
key:key4 value:4