36_Go基础_1_3 iota

 1 package main
 2 
 3 import (
 4     "fmt"
 5 )
 6 
 7 func main() {
 8     /*
 9         iota:特殊的常量,可以被编译器自动修改的常量
10             每当定义一个const,iota的初始值为0
11             每当定义一个常量,就会自动累加1
12             直到下一个const出现,清零
13     */
14     const (
15         a = iota // 0
16         b = iota // 1
17         c = iota // 2
18     )
19     fmt.Println(a)
20     fmt.Println(b)
21     fmt.Println(c)
22 
23     const (
24         d = iota // 0
25         e        // 1
26     )
27     fmt.Println(d)
28     fmt.Println(e)
29 
30     //枚举中
31     const (
32         MALE   = iota // 0
33         FEMALE        // 1
34         UNKNOW        // 2
35     )
36     fmt.Println(MALE, FEMALE, UNKNOW)
37 
38 }
原文地址:https://www.cnblogs.com/luwei0915/p/15617486.html