Keyword

Go map keyword

Defines a mapping from keys to values. Key types must support equality; interface keys must also have comparable dynamic values when used. Missing keys yield the value type’s zero value; use the comma-ok form to distinguish absence. Example prints 3 true.

Formal Syntax & Structure

go syntaxgo
map[Key]Value

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  stock := map[string]int{"pen": 3}  n, ok := stock["pen"]  fmt.Println(n, ok)}
Go Reference