package main
import (
"fmt"
)
func main(){
var test = map[string]string{"Name":"Li Si","Gender":"Male"}
name,ok := test["name"] // If the key exists, then name = Li Si, ok = true, otherwise, ok = false
if ok{
(name)
}
delete(test,"name")//Delete as a value with the name key, it doesn't matter if it doesn't exist.
(test)
var a map[string]string
a["b"] = "c"//This will report an error. You must initialize the memory first.
a = make(map[string]string)
a["b"] = "c"//This way you won't be wrong
}
import (
"fmt"
)
func main(){
var test = map[string]string{"Name":"Li Si","Gender":"Male"}
name,ok := test["name"] // If the key exists, then name = Li Si, ok = true, otherwise, ok = false
if ok{
(name)
}
delete(test,"name")//Delete as a value with the name key, it doesn't matter if it doesn't exist.
(test)
var a map[string]string
a["b"] = "c"//This will report an error. You must initialize the memory first.
a = make(map[string]string)
a["b"] = "c"//This way you won't be wrong
}