Tinywan 7 years ago
parent e7e6e52d4f
commit 741d9b9f8a

@ -73,8 +73,9 @@ $ go get github.com/Tinywan/golang-tutorial
### 34 - 反射
### [35 - 读文件](/docs/golang_tutorial_35.md)
## 其他文档
* [如何编写Go代码](/docs/how_to_write_go_code.md)
## 文档
* [Go 零基础编程入门教程](http://go-courses.tinywan.com/_book/)
* [Go 语言标准库](http://go-library.tinywan.com/_book/)
* [如何编写 Go代码](/docs/how_to_write_go_code.md)
* [原文](https://golangbot.com/)

@ -0,0 +1,5 @@
package main
func main() {
}

@ -4,9 +4,16 @@ import (
"fmt"
)
func main(){
func main() {
b := 255
var a = &b
fmt.Printf("Type of a is %T\n",a)
fmt.Println("address of b is",a)
fmt.Printf("Type of a is %T\n", a)
fmt.Println("address of b is", a)
s := map[string]int{"age": 24}
var t map[string]string // 正确
t1 := map[string]string // 错误
fmt.Println(s)
fmt.Println(t)
fmt.Println(t1)
}

@ -0,0 +1,47 @@
package main
import (
"fmt"
"reflect"
)
// import (
// "fmt"
// ) go_basic_courses
func main() {
// 声明一个集合字典,默认为空
a := 15
fmt.Println("address of b is ", a)
fmt.Println("address of b is ", &a)
m := map[string]int{}
fmt.Println("address of b i is ", m)
fmt.Printf("Type of a is %T\n", m)
fmt.Printf("m值是 %v \n", m == nil)
var dir map[string]string
fmt.Printf("dir字典的值是: | %v \n", dir)
fmt.Printf("dir字典是否为nil | %v \n", dir == nil)
// nil map不能赋值,如果直接赋值会报错“panic: assignment to entry in nil map”下面语句将会报错
// dir["name"] = "Tinywan"
fmt.Println("----------------------------")
// 使用make函数进行初始化创建一个非nil的map
dir = make(map[string]string)
// map是引用类型未初始化的是指向nil初始化了以后应该就有自己的内存空间了所以不是nil
fmt.Printf("dir字典的值是: | %v \n", dir)
fmt.Printf("dir字典是否为nil | %v \n", dir == nil)
fmt.Println("----------------------------")
// make之后分配内存了,一旦分配了内存地址就不为空了,可以赋值了
dir["name"] = "Tinywan"
fmt.Printf("dir字典的键:值 |%v \n", dir)
fmt.Printf("dir字典的类型 |%v \n", reflect.TypeOf(dir))
fmt.Printf("name的值是 |%v \n", dir["name"])
// value, ok := s["ok"]
// if ok == nil {
// s := make(map[string]int)
// s["ok"] = 19
// fmt.Println(s["ok"])
// }
// fmt.Println(s["ok"])
}
Loading…
Cancel
Save