标签:
m := make(map[string]int) m["Answer"] = 48 v, ok := m["Answer"] fmt.Println("The value:", v, "Present?", ok) delete(m, "Answer") fmt.Println("The value:", v, "Present?", ok)
The value: 48 Present? true
The value: 0 Present? false
func main() { a := make([]int, 5) printSlice("a", a) b := make([]int, 0, 5) printSlice("b", b) c := b[:2] printSlice("c", c) d := c[2:5] printSlice("d", d) printSlice("b", b) } func printSlice(s string, x []int) { fmt.Printf("%s len=%d cap=%d %v\n", s, len(x), cap(x), x) }
a len=5 cap=5 [0 0 0 0 0]
b len=0 cap=5 []
c len=2 cap=5 [0 0]
d len=3 cap=3 [0 0 0]
b len=0 cap=5 []
var pow = []string{"hehe", "haha"} for i, v := range pow { fmt.Printf("2**%d = %s\n", i, v) }
2**0 = hehe
2**1 = haha
标签:
原文地址:http://www.cnblogs.com/briller/p/4180671.html