-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.go
96 lines (84 loc) · 1.3 KB
/
basic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"math"
"math/cmplx"
)
//包内变量
var (
aa = 3
ss = "kkk"
bb = true
)
func variableZeroValue() {
var a int
var s string
fmt.Printf("%d %q\n", a, s)
}
func variableInitialValue() {
var a, b = 3, 4
var s = "abc"
fmt.Println(a, b, s)
}
func variableTypeDeduction() {
var a, b, c, s = 3, 4, true, "def"
fmt.Println(a, b, c, s)
}
func variableShorter() {
// := 声明变量 不需要var关键字,只能在函数内使用
a, b, c, s := 3, 4, true, "def"
d := 5
fmt.Println(a, b, c, s, d)
}
func eulaer() {
c := cmplx.Exp(1i*math.Pi) + 1
fmt.Printf("%.3f\n", c)
}
func triangle() {
var a, b int = 2, 5
var c int
c = int(math.Sqrt(float64(a*a + b*b)))
fmt.Println(c)
}
func consts() {
// const数值可以作为各种类型使用
const (
filename = "abc.txt"
a, b = 3, 4
)
var c int
c = int(math.Sqrt(a*a + b*b))
fmt.Println(filename, c)
}
func enums() {
const (
cpp = iota
_
java
python
golang
)
//b,kb,mb,gb
const (
b = 1 << (10 * iota)
kb
mb
gb
tb
pb
)
fmt.Println(cpp, java, python, golang)
fmt.Println(b, kb, mb, gb, tb, pb)
}
func main() {
fmt.Println("hello world")
variableZeroValue()
variableInitialValue()
variableTypeDeduction()
variableShorter()
fmt.Println(aa, ss, bb)
eulaer()
triangle()
consts()
enums()
}