You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
419 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import "fmt"
func main() {
m := make(map[string]int)
m["k1"] = 7
m["k2"] = 8
m["k3"] = 9
fmt.Println(m)
// 获取键值
v1 := m["k2"]
fmt.Println(v1)
// 长度
fmt.Println(len(m))
// 移除键值对
delete(m, "k1")
fmt.Println(m)
// 从map中取值第二个值判断值是否存在
_, prs := m["k2"]
fmt.Println(prs)
n := map[int]string{1: "test1", 2: "test2"}
fmt.Println(n)
}