go语言学习笔记—iota
package main
import "fmt"
func main() {
// itoa : 常量自动生成器
//1.常量赋值,每隔一行,自动加一
const (
a = iota
b = iota
c = iota
)
fmt.Printf("a=%d,b=%d,c=%d\n", a, b, c)
//2.itoa遇到const时,会重置为0
const d = iota
fmt.Println("d=", d)
//3.可以只写一个itoa
const (
e = iota
f
g
)
fmt.Printf("e=%d,f=%d,g=%d\n", e, f, g)
// 如果是一行,值是一样的
const (
h = iota
i, j, k = iota, iota, iota
l = iota
)
fmt.Printf("h=%d,i=%d,j=%d,k=%d,l=%d\n", h, i, j, k, l)
}
执行结果: