The built-in delete(m, k) removes the entry for key k from map m. If k is absent, the call is a no-op—no panic. Other languages call similar structures dictionaries or hash maps; in Python the ideas overlap with a Python dictionary. For Go basics, read maps in Go.
Tested with Go 1.24 on Linux.
Delete without checking
package main
import "fmt"
func main() {
studentsScore := map[string]int{
"Anna": 5, "Bob": 9, "Clair": 8, "Daniel": 10,
}
fmt.Println(studentsScore)
fmt.Println("Deleting Bob")
delete(studentsScore, "Bob")
fmt.Println("Deleting Eve (missing key)")
delete(studentsScore, "Eve")
fmt.Println(studentsScore)
}You should see Bob removed and the map unchanged by the Eve delete beyond losing nothing.
Delete when the key exists
package main
import "fmt"
func deleteKey(m map[string]int, key string) {
if _, ok := m[key]; ok {
delete(m, key)
} else {
fmt.Println(key, "is not in the map")
}
}
func main() {
studentsScore := map[string]int{
"Anna": 5, "Bob": 9, "Clair": 8, "Daniel": 10,
}
fmt.Println(studentsScore)
deleteKey(studentsScore, "Bob")
deleteKey(studentsScore, "Eve")
fmt.Println(studentsScore)
}You should see a line reporting Eve is not in the map, then the map without Bob.
Summary
To golang delete from map data, call delete(m, k); it is safe on missing keys. When you need explicit handling, gate the delete with the comma-ok read. Pair deletes with clear map semantics from your functions or methods so callers know whether absence is normal.

