go_study/bilibili/aceid/const/test.go
2024-11-14 18:01:59 +08:00

38 lines
894 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
)
const (
// 可以在const()添加一个关键字iota每行的iota都会累加1 第一行的iota默认值是0
BEIJING = 10 * iota
SHANGHAI
SHENZHEN
)
const (
a, b = iota + 1, iota + 2 // iota = 0, a = 1, b = 2
c, d // iota = 1, c = 2, d = 3
e, f // iota = 2, e = 3, f = 4
g, h = iota * 2, iota * 3 // iota = 3, g = 3 * 2 = 6, h = 3 * 3 = 9
i, k // iota = 4, i = 4 * 2 = 8, k = 4 * 3 = 12
)
func main() {
// 常量(只读属性)
const length int = 10
fmt.Println("length = ", length)
fmt.Println("BEIJING = ", BEIJING)
fmt.Println("SHANGHAI = ", SHANGHAI)
fmt.Println("SHENZHEN = ", SHENZHEN)
fmt.Println("a = ", a, "b = ", b)
fmt.Println("c = ", c, "d = ", d)
fmt.Println("e = ", e, "f = ", f)
fmt.Println("g = ", g, "h = ", h)
fmt.Println("i = ", i, "k = ", k)
}