Skip to content

Commit 834b949

Browse files
committed
更新排便
1 parent 959c67f commit 834b949

File tree

13 files changed

+180
-177
lines changed

13 files changed

+180
-177
lines changed

example/array/array.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import "fmt"
33
func main() {
44
// 声明一个长度为5的整数数组
55
// 一旦数组被声明了,那么它的数据类型跟长度都不能再被改变。
6-
var array1 [5]int
7-
8-
fmt.Printf("array1: %d\n\n", array1)
6+
var array1 [5]int
7+
8+
fmt.Printf("array1: %d\n\n", array1)
99

1010
// 声明一个长度为5的整数数组
1111
// 初始化每个元素
1212
array2 := [5]int{12, 123, 1234, 12345, 123456}
1313
array2[1] = 5000
14-
fmt.Printf("array2: %d\n\n", array2[1])
15-
14+
fmt.Printf("array2: %d\n\n", array2[1])
15+
1616
// n 是一个长度为 10 的数组
1717
var n [10]int
1818
var i,j int

example/byte/byte.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
package main
22
import (
3-
"bytes"
4-
"fmt"
3+
"bytes"
4+
"fmt"
55
)
66
func main() {
7-
// 这里不能写成 b := []byte{"Golang"},这里是利用类型转换。
8-
b := []byte("Golang")
9-
subslice1 := []byte("go")
10-
subslice2 := []byte("Go")
11-
// func Contains(b, subslice [] byte) bool
12-
// 检查字节切片b ,是否包含子字节切片 subslice
13-
fmt.Println(bytes.Contains(b, subslice1))
14-
fmt.Println(bytes.Contains(b, subslice2))
15-
16-
17-
s2 := []byte("同学们,上午好")
18-
m := func(r rune) rune {
19-
if r == '上' {
20-
r = '下'
21-
}
22-
return r
23-
}
24-
fmt.Println(string(s2))
25-
// func Map(mapping func(r rune) rune, s []byte) []byte
26-
// Map函数: 首先将 s 转化为 UTF-8编码的字符序列,
27-
// 然后使用 mapping 将每个Unicode字符映射为对应的字符,
28-
// 最后将结果保存在一个新的字节切片中。
29-
fmt.Println(string(bytes.Map(m, s2)))
30-
31-
32-
s3 := []byte("google")
33-
old := []byte("o")
34-
//这里 new 是一个字节切片,不是关键字了
35-
new := []byte("oo")
36-
n := 1
37-
// func Replace(s, old, new []byte, n int) []byte
38-
//返回字节切片 S 的一个副本, 并且将前n个不重叠的子切片 old 替换为 new,如果n < 0 那么不限制替换的数量
39-
fmt.Println(string(bytes.Replace(s3, old, new, n)))
40-
fmt.Println(string(bytes.Replace(s3, old, new, -1)))
41-
42-
43-
// 将字节切片 转化为对应的 UTF-8编码的字节序列,并且返回对应的 Unicode 切片。
44-
s4 := []byte("中华人民共和国")
45-
r1 := bytes.Runes(s4)
46-
// func Runes(b []byte) []rune
47-
fmt.Println(string(s4), len(s4)) // 字节切片的长度
48-
fmt.Println(string(r1), len(r1)) // rune 切片的长度
49-
50-
51-
// 字节切片 的每个元素,依旧是字节切片。
52-
s5 := [][]byte{
53-
[]byte("你好"),
54-
[]byte("世界"), //这里的逗号,必不可少
55-
}
56-
sep := []byte(",")
57-
// func Join(s [][]byte, sep []byte) []byte
58-
// 用字节切片 sep 吧 s中的每个字节切片连接成一个,并且返回.
59-
fmt.Println(string(bytes.Join(s5, sep)))
7+
// 这里不能写成 b := []byte{"Golang"},这里是利用类型转换。
8+
b := []byte("Golang")
9+
subslice1 := []byte("go")
10+
subslice2 := []byte("Go")
11+
// func Contains(b, subslice [] byte) bool
12+
// 检查字节切片b ,是否包含子字节切片 subslice
13+
fmt.Println(bytes.Contains(b, subslice1))
14+
fmt.Println(bytes.Contains(b, subslice2))
15+
16+
17+
s2 := []byte("同学们,上午好")
18+
m := func(r rune) rune {
19+
if r == '上' {
20+
r = '下'
21+
}
22+
return r
23+
}
24+
fmt.Println(string(s2))
25+
// func Map(mapping func(r rune) rune, s []byte) []byte
26+
// Map函数: 首先将 s 转化为 UTF-8编码的字符序列,
27+
// 然后使用 mapping 将每个Unicode字符映射为对应的字符,
28+
// 最后将结果保存在一个新的字节切片中。
29+
fmt.Println(string(bytes.Map(m, s2)))
30+
31+
32+
s3 := []byte("google")
33+
old := []byte("o")
34+
//这里 new 是一个字节切片,不是关键字了
35+
new := []byte("oo")
36+
n := 1
37+
// func Replace(s, old, new []byte, n int) []byte
38+
//返回字节切片 S 的一个副本, 并且将前n个不重叠的子切片 old 替换为 new,如果n < 0 那么不限制替换的数量
39+
fmt.Println(string(bytes.Replace(s3, old, new, n)))
40+
fmt.Println(string(bytes.Replace(s3, old, new, -1)))
41+
42+
43+
// 将字节切片 转化为对应的 UTF-8编码的字节序列,并且返回对应的 Unicode 切片。
44+
s4 := []byte("中华人民共和国")
45+
r1 := bytes.Runes(s4)
46+
// func Runes(b []byte) []rune
47+
fmt.Println(string(s4), len(s4)) // 字节切片的长度
48+
fmt.Println(string(r1), len(r1)) // rune 切片的长度
49+
50+
51+
// 字节切片 的每个元素,依旧是字节切片。
52+
s5 := [][]byte{
53+
[]byte("你好"),
54+
[]byte("世界"), //这里的逗号,必不可少
55+
}
56+
sep := []byte(",")
57+
// func Join(s [][]byte, sep []byte) []byte
58+
// 用字节切片 sep 吧 s中的每个字节切片连接成一个,并且返回.
59+
fmt.Println(string(bytes.Join(s5, sep)))
6060
}

example/const/const.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import "unsafe"
44
// 常量可以用len(), cap(), unsafe.Sizeof()常量计算表达式的值。
55
// 常量表达式中,函数必须是内置函数,否则编译不过:
66
const (
7-
a = "abc"
8-
b = len(a)
9-
c = unsafe.Sizeof(a)
7+
a = "abc"
8+
b = len(a)
9+
c = unsafe.Sizeof(a)
1010
)
1111

1212
func main(){
13-
const (
14-
PI = 3.14
15-
const1 = "1"
16-
)
17-
const LENGTH int = 10
18-
const e, f, g = 1, false, "str" //多重赋值
19-
println(a, b, c,PI, LENGTH)
13+
const (
14+
PI = 3.14
15+
const1 = "1"
16+
)
17+
const LENGTH int = 10
18+
const e, f, g = 1, false, "str" //多重赋值
19+
println(a, b, c,PI, LENGTH)
2020
}

example/float/float.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func main() {
77
fmt.Println(x)
88
fmt.Printf("x is of type %T\n", x)
99

10-
a := float64(20.0)
10+
a := float64(20.0)
1111
b := 42
1212
fmt.Println(a)
1313
fmt.Println(b)

example/func/func.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package main
22
import "fmt"
3+
34
type functinTyoe func(int, int)// // 声明了一个函数类型
5+
46
func (f functinTyoe)Serve() {
57
fmt.Println("serve2")
68
}
9+
710
func serve(int,int) {
811
fmt.Println("serve1")
912
}
13+
1014
func main() {
1115
a := functinTyoe(serve)
1216
a(1,2)

example/inteface/inteface.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
11
package main
22
import (
3-
"fmt"
4-
"math"
3+
"fmt"
4+
"math"
55
)
66

77
/* 定义一个 interface */
88
type shape interface {
9-
area() float64
9+
area() float64
1010
}
1111

1212
/* 定义一个 circle */
1313
type circle struct {
14-
x,y,radius float64
14+
x,y,radius float64
1515
}
1616

1717
/* 定义一个 rectangle */
1818
type rectangle struct {
19-
width, height float64
19+
width, height float64
2020
}
2121

2222
/* 定义一个circle方法 (实现 shape.area())*/
2323
func(circle circle) area() float64 {
24-
return math.Pi * circle.radius * circle.radius
24+
return math.Pi * circle.radius * circle.radius
2525
}
2626

2727
/* 定义一个rectangle方法 (实现 shape.area())*/
2828
func(rect rectangle) area() float64 {
29-
return rect.width * rect.height
29+
return rect.width * rect.height
3030
}
3131

3232
/* 定义一个shape的方法*/
3333
func getArea(shape shape) float64 {
34-
return shape.area()
34+
return shape.area()
3535
}
3636

3737
func main() {
38-
circle := circle{x:0,y:0,radius:5}
39-
rectangle := rectangle {width:10, height:5}
38+
circle := circle{x:0,y:0,radius:5}
39+
rectangle := rectangle {width:10, height:5}
4040

41-
fmt.Printf("circle area: %f\n",getArea(circle))
42-
fmt.Printf("rectangle area: %f\n",getArea(rectangle))
43-
}
41+
fmt.Printf("circle area: %f\n",getArea(circle))
42+
fmt.Printf("rectangle area: %f\n",getArea(rectangle))
43+
}
44+

example/iota/iota.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package main
22
import "fmt"
33
func main() {
4-
const (
5-
// 第一个 iota 等于 0,每当 iota 在新的一行被使用时,它的值都会自动加 1;
6-
// 所以 a=0, b=1, c=2 可以简写为如下形式:
7-
a = iota //0
8-
b //1
9-
c //2
10-
d = "ha" //独立值,iota += 1
11-
e //"ha" iota += 1
12-
f = 100 //iota +=1
13-
g //100 iota +=1
14-
h = iota //7,恢复计数
15-
i //8
16-
)
17-
fmt.Println(a,b,c,d,e,f,g,h,i)
4+
const (
5+
// 第一个 iota 等于 0,每当 iota 在新的一行被使用时,它的值都会自动加 1;
6+
// 所以 a=0, b=1, c=2 可以简写为如下形式:
7+
a = iota //0
8+
b //1
9+
c //2
10+
d = "ha" //独立值,iota += 1
11+
e //"ha" iota += 1
12+
f = 100 //iota +=1
13+
g //100 iota +=1
14+
h = iota //7,恢复计数
15+
i //8
16+
)
17+
fmt.Println(a,b,c,d,e,f,g,h,i)
1818
}

example/package-demo/cal/add.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cal
22

33
func Add(num1 int,num2 int) (result int) {
4-
return num1 + num2
5-
}
6-
4+
return num1 + num2
5+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package multi
22

33
func Multi(num1 int, num2 int) (result int) {
4-
return num1 * num2
4+
return num1 * num2
55
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cal
22

33
func Subtract(num1 int,num2 int) (result int) {
4-
return num1 + num2
5-
}
6-
4+
return num1 + num2
5+
}

0 commit comments

Comments
 (0)