【golang】1.0 go语言入门:数据类型、常量、枚举

image.png

image.png

image.png
**Go Download Installation Address** Go Download - Go Language Chinese Website - Golang Chinese Community (studygolang.com)
**Chinese Mirror** Qiniu Cloud - Goproxy.cn
Open your terminal and execute
$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct
**Development Software**
Goland/Intellij Idea + Go Plugin
VS Code
**New Project**
GoMod: learngo
go 1.18
**Version and Installation Go Version Consistency**
module learngo
go 1.18
**Create go.mod**
module main
import "fmt"
func main() {
fmt.Println("hello world basic")
}
**Run Configuration**

image.png
**Alternative Run Method**

image.png
...
func enums() {
const (
cpp = iota
java
python
golang
)
fmt.Println(cpp, java, python, golang)
const (
b = 1 << (10*iota)
kb
mb
gb
tb
pb
)
fmt.Println(b, mb, gb, tb, pb)
}
func main() {
enums()
}
**Type Conversion**
Go only supports explicit type conversion, no implicit conversions.
...
func triangle() {
var a, b int = 3, 4
var c int
c = int(math.Sqrt(float64(a*a + b*b)))
fmt.Println(c)
}
func main() {
triangle()
}
**Constants**
Go's uppercase constants have meaning.
...
func consts() {
const (
filename = "abc.txt"
a, b = 3, 4
)
var c int
c = int(math.Sqrt(float64(a*a + b*b)))
fmt.Println(filename, c)
}
func main() {
consts()
}
**Enum Types**
Go lacks specific enum types, usually defined via constants.
...
func enums() {
const (
cpp = iota
java
python
golang
)
fmt.Println(cpp, java, python, golang)
const (
b = 1 << (10*iota)
kb
mb
gb
tb
pb
)
fmt.Println(b, mb, gb, tb, pb)
}
func main() {
enums()
}
---
**Final Notes**
- All code snippets preserved with proper formatting.
- Technical terms like "type conversion" and "enum types" retained.
- Links and file names kept as-is for consistency.
- Structure maintained for readability and technical accuracy.