Skip to content

Commit 741d9b9

Browse files
committed
http://go-courses.tinywan.com/_book/ch7/ch7/ch7/ch7/ch7/ch7/ch7/ch7/channel.html
Signed-off-by: Tinywan <756684177@qq.com>
1 parent e7e6e52 commit 741d9b9

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ $ go get github.com/Tinywan/golang-tutorial
7373
### 34 - 反射
7474
### [35 - 读文件](/docs/golang_tutorial_35.md)
7575

76-
## 其他文档
77-
78-
* [如何编写Go代码](/docs/how_to_write_go_code.md)
76+
## 文档
77+
* [Go 零基础编程入门教程](http://go-courses.tinywan.com/_book/)
78+
* [Go 语言标准库](http://go-library.tinywan.com/_book/)
79+
* [如何编写 Go代码](/docs/how_to_write_go_code.md)
7980
* [原文](https://golangbot.com/)
8081

demo/channel/demo01.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package main
2+
3+
func main() {
4+
5+
}

demo/point/demo.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import (
44
"fmt"
55
)
66

7-
func main(){
7+
func main() {
88
b := 255
99
var a = &b
10-
fmt.Printf("Type of a is %T\n",a)
11-
fmt.Println("address of b is",a)
12-
}
10+
fmt.Printf("Type of a is %T\n", a)
11+
fmt.Println("address of b is", a)
12+
13+
s := map[string]int{"age": 24}
14+
var t map[string]string // 正确
15+
t1 := map[string]string // 错误
16+
fmt.Println(s)
17+
fmt.Println(t)
18+
fmt.Println(t1)
19+
}

demo/point/dmoe002.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"reflect"
6+
)
7+
8+
// import (
9+
// "fmt"
10+
// ) go_basic_courses
11+
12+
func main() {
13+
// 声明一个集合字典,默认为空
14+
a := 15
15+
fmt.Println("address of b is ", a)
16+
fmt.Println("address of b is ", &a)
17+
m := map[string]int{}
18+
fmt.Println("address of b i is ", m)
19+
fmt.Printf("Type of a is %T\n", m)
20+
fmt.Printf("m值是 %v \n", m == nil)
21+
var dir map[string]string
22+
fmt.Printf("dir字典的值是: | %v \n", dir)
23+
fmt.Printf("dir字典是否为nil | %v \n", dir == nil)
24+
// nil map不能赋值,如果直接赋值会报错:“panic: assignment to entry in nil map”,下面语句将会报错
25+
// dir["name"] = "Tinywan"
26+
27+
fmt.Println("----------------------------")
28+
// 使用make函数进行初始化创建一个非nil的map
29+
dir = make(map[string]string)
30+
// map是引用类型,未初始化的是指向nil,初始化了以后应该就有自己的内存空间了,所以不是nil
31+
fmt.Printf("dir字典的值是: | %v \n", dir)
32+
fmt.Printf("dir字典是否为nil | %v \n", dir == nil)
33+
34+
fmt.Println("----------------------------")
35+
// make之后分配内存了,一旦分配了内存地址就不为空了,可以赋值了
36+
dir["name"] = "Tinywan"
37+
fmt.Printf("dir字典的键:值 |%v \n", dir)
38+
fmt.Printf("dir字典的类型 |%v \n", reflect.TypeOf(dir))
39+
fmt.Printf("name的值是 |%v \n", dir["name"])
40+
// value, ok := s["ok"]
41+
// if ok == nil {
42+
// s := make(map[string]int)
43+
// s["ok"] = 19
44+
// fmt.Println(s["ok"])
45+
// }
46+
// fmt.Println(s["ok"])
47+
}

0 commit comments

Comments
 (0)