Collections and Composite Types
Maps
Maps store values by key, which makes lookup code direct.
Maps
maps_intro.go
package main
import "fmt"
func main() {
var key =
scores := map[string]int{
"go": 95,
"ruby": 88,
"python": 92,
}
value := scores[key]
fmt.Println("key=", key)
fmt.Println("value=", value)
}
package main
import "fmt"
func main() {
var key =
scores := map[string]int{
"go": 95,
"ruby": 88,
"python": 92,
}
value := scores[key]
fmt.Println("key=", key)
fmt.Println("value=", value)
}
package main
import "fmt"
func main() {
var key =
scores := map[string]int{
"go": 95,
"ruby": 88,
"python": 92,
}
value := scores[key]
fmt.Println("key=", key)
fmt.Println("value=", value)
}
map lookup
A map lookup such as `scores[key]` returns the value stored for that key.