golang快速入门-03-golang的常量和iota
0 const length int = 10
1 //const 来定义枚举类型 2 const ( 3 //可以在const() 添加一个关键字 iota, 每行的iota都会累加1, 第一行的iota的默认值是0 4 BEIJING = iota //iota = 0 5 SHANGHAI //iota = 1 6 SHENZHEN //iota = 2 7 ) 8 9 10 //const 来定义枚举类型 11 const ( 12 //可以在const() 添加一个关键字 iota, 每行的iota都会累加1, 第一行的iota的默认值是0 13 BEIJING = 10*iota //iota = 0 14 SHANGHAI //iota = 10 15 SHENZHEN //iota = 20 16 ) 17 18 // 公式继承,直到被覆盖 19 const ( 20 a, b = iota+1, iota+2 // iota = 0, a = iota + 1, b = iota + 2, a = 1, b = 2 21 c, d // iota = 1, c = iota + 1, d = iota + 2, c = 2, d = 3 22 e, f // iota = 2, e = iota + 1, f = iota + 2, e = 3, f = 4 23 24 g, h = iota * 2, iota *3 // iota = 3, g = iota * 2, h = iota * 3, g = 6, h = 9 25 i, k // iota = 4, i = iota * 2, k = iota * 3 , i = 8, k = 12 26 )
浙公网安备 33010602011771号