Maps
Context
Section titled “Context”A map is an unordered collection of key‑value pairs. Keys must be comparable types. Maps are reference types; nil maps behave like empty maps but cannot be assigned to.
Example
Section titled “Example”Create, insert, look up, and delete entries.
Code example
Section titled “Code example”package main
import "fmt"
func main() { m := make(map[string]int) m["apple"] = 5 m["banana"] = 7
fmt.Println(m["apple"]) fmt.Println(len(m))
delete(m, "banana")
value, ok := m["banana"] fmt.Printf("value=%d, ok=%v\n", value, ok)
literal := map[string]int{"x": 1, "y": 2} fmt.Println(literal)}Output
Section titled “Output”52value=0, ok=falsemap[x:1 y:2]