if中用分号是否奇怪?
```go var f os.File if f, err := os.Open("file"); err != nil { //分号没有被括号包含,感觉分号后面像是另外一行 } ``` 其它语言中if中都没有分号,怎么go看起来怪怪...阅读全文
```go var f os.File if f, err := os.Open("file"); err != nil { //分号没有被括号包含,感觉分号后面像是另外一行 } ``` 其它语言中if中都没有分号,怎么go看起来怪怪...阅读全文
Maps are Go's built-in associative data type(sometimes called hashes or dits in other languages) package main import ( "fmt" ) func main() { m := make(map[string]int) m["k1"] = 7 m["k2"] = 13 fmt.Println("map :", m) v1 := m["k1"] fmt.Println("v1 :", v1) fmt.Println("len : ", len(m)) delete(m, "k2") fmt.Println("map:", m) a, prs := m["k2"] fmt.Print...阅读全文
go语言iota有点奇怪,看下面代码: package main import ( "fmt" ) const ( TestMin = -1 TestA TestB = iota TestC ) func main() { fmt.Printf("TestMin:%d\n", TestMin) fmt.Printf("TestA:%d\n", TestA) fmt.Printf("TestB:%d\n", TestB) fmt.Printf("TestC:%d\n", TestC) } 上面代码的执行结果是什么呢? 结果是这样的,看到结果,对iota的用法就基本掌握了: /* TestMin:-1 TestA:-1 TestB:2 TestC:3 */ 再来看一例: package main...阅读全文