Map element exists
- The variable name ok is not speacial. It is just a convention.
examples/exists/exists.go
package main import "fmt" func main() { grades := make(map[string]int) grades["Mary"] = 99 grades["Joe"] = 0 value, ok := grades["Mary"] fmt.Println(ok) fmt.Println(value) fmt.Println() value, ok = grades["Joe"] fmt.Println(ok) fmt.Println(value) fmt.Println() value, ok = grades["Jane"] fmt.Println(ok) fmt.Println(value) }
true 99 true 0 false 0