Skip to content

Commit a14fc5e

Browse files
committed
update lesson3 and lesson7
1 parent 6d28146 commit a14fc5e

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

workspace/lesson3/readme.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,56 @@
8484
a1, b1 := 1, "str"
8585
```
8686

87-
87+
* 变量类型
88+
89+
* 数值:整数,浮点数,复数
90+
91+
* bool
92+
93+
* 字符串
94+
95+
* 指针:var a *int
96+
97+
```go
98+
num := 100
99+
var a * int = &num
100+
```
101+
102+
* 数组:var a []int
103+
104+
```go
105+
var a []int = []int{1,2}
106+
list := [6]int{1,2} //size为6的数组,前面2个元素是1和2,后面的是默认值0
107+
```
108+
109+
* mapvar a map[string] int
110+
111+
```go
112+
dict := map[string] int{"a":1, "b":2}
113+
```
114+
115+
* 函数:var a func(string) int
116+
117+
```go
118+
function := func(str string) string {
119+
return str
120+
}
121+
result := function("hello fans")
122+
fmt.Println("result=", result)
123+
```
124+
125+
* 结构体: var instance Struct
126+
127+
```go
128+
type Circle struct {
129+
redius float64
130+
}
131+
132+
var c1 Circle
133+
c1.radius = 10.00
134+
```
135+
136+
* channel:var a chan int
137+
138+
* 接口:var a error // error是接口
88139

workspace/lesson3/variable.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ func main() {
5858
var b2 int
5959
b2 = 200
6060
fmt.Println(b2)
61+
62+
63+
function := func(a string) string {
64+
return a
65+
}
66+
result := function("hello")
67+
fmt.Println("result=", result)
6168
}

workspace/lesson7/control-each.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ func main() {
1111
println("index=", index, "value=", value)
1212
}
1313

14+
var list []int = []int{1,2}
15+
for index, value := range list {
16+
println("index=", index, "value=", value)
17+
}
1418
strings := []string{"google", "nb"} // 2个元素的字符串数组
1519
for index, value := range strings {
1620
println("index=", index, "value=", value)
1721
}
22+
23+
dict := map[string] int{"a":1, "b":2}
24+
for key, value := range dict {
25+
println("key=", key, "value=", value)
26+
}
1827
}

0 commit comments

Comments
 (0)