字典复制

数组和集合 / 字典

import (
    "fmt"
    "maps"
)

var d1 = map[int]string{
    1: "one", 2: "two", 3: "tree" }

var d2 = maps.Clone(d1)
d2[3] = "three"

//d1 is map[1:one 2:two 3:tree]
//d2 is map[1:one 2:two 3:three]
fmt.Println("d1 is", d1)
fmt.Println("d2 is", d2)